Rails, Cucumber, Capybara, Selenium, Pow, domains, subdomains and javascript

TL: DR - How can I make Cucumber request a page through an application, but pretend the request came from "http://mysubdomain.mydomain.dev" and run javascript correctly?

Ok, it may take some time to explain, but please carry me ...

I am a "relatively" experienced Rails developer, but only recently plunged into a full-fledged BDD / TDD.

The page I'm testing in a cucumber contains some javascript to create a new nested object (very similar to this RailsCast ).

Now the problem is that I have not only variable subdomains, but also variable Domains (just trust me on this ...)

Therefore, the application must query request.hostto find current_domainand current_subdomainbefore everything communicates in the background, and it can continue to serve the desired bits of the application.

I managed to get all the tests passing perfectly using the methods host! domainand Capybara.default_host = domainin the background steps.

However, when I use the @javascript tag for a function that checks the page using .js, I get Firefox focus and then try to load the full URL.

Now it also happens that I run Pow and bind these URLs to the dev server. Not surprisingly, they do not work when a user tries to log in by looking in Dev DB. I tried to start the package after turning off the pow server, and it is just timed.

, - javascript URL-, , - , .

- . Cucumber , , "http://mysubdomain.mydomain.dev"?

: Jason - , ... db request.subdomains.first, request.domain. , , .., URL-, , , , db ...

Oh - ...

, , .. PaaS - , .

+5
1

- . pow , pow, . , ".powenv" . :

echo export RAILS_ENV=cucumber > .powenv && touch tmp/restart.txt

- , , , , env, , , , . Pow - , .

EDITED: features/support/env.rb.

# Switch Pow to For Cucumber Tests
Capybara.default_driver = :selenium # Subdomain testing will only work with pow and selenium
pow_config = "#{Rails.root}/.powenv" # Dont change, this is the Config Files Location.
pow_config_stash = "#{Rails.root}/.powenv_original" # This is what the config will be stashed as during testing.

Before do

  # Set the default host
  Capybara.app_host = "http://www.resipsa.dev"

  # Stash the existing config
  File.rename(pow_config,pow_config_stash) if File.exists? pow_config

  # Write the new pow config
  f = File.new("#{Rails.root}/.powenv", "w")
  f.write "export RAILS_ENV=test"
  f.close

  # Touch tmp/restart.txt to force a restart
  FileUtils.touch "#{Rails.root}/tmp/restart.txt"

end

After do

  # Delete the temp config
  File.delete(pow_config)

  # Restore the Original Config
  File.rename(pow_config_stash,pow_config) if File.exists? pow_config_stash

  # Touch tmp/restart.txt to force a restart
  FileUtils.touch "#{Rails.root}/tmp/restart.txt"

end
+4

All Articles