vendredi 23 janvier 2015

How do I check for the test environment in coffeescript for rails?

I have some coffeescript code that I want to avoid when running my integration tests and cucumber scenarios. I'm trying to figure out if there is an easy way to introspect on the runtime environment so that if it's 'test', it will do one thing, else do another thing.


I don't want to add ERB parsing to the coffeescript file. Is there any other way to know if it's running in test environment?


Here's the snippit. It sets up a window alert when you leave the page. This is messing up my cucumber code, so I want to simply skip it if I'm running under Rails.env == 'test'



setupNavigateAwayProtection: ->
window.onbeforeunload = =>
if @promptForChanges()
message = "You are about to lose your changes"
message


promptForChanges is a function that checks if the content has changed. So I could imagine a version like:



window.onbeforeunload = =>
if @promptForChanges() && !@test
message = "You are about to lose your changes"
message


but how would I define @test to be true if I'm running tests?


Thanks, Dan


Aucun commentaire:

Enregistrer un commentaire