Paul
Paul

Reputation: 36349

Cucumber and Capybara test failing, how do I debug?

I am brand new to testing w/ Capybara and Cucumber. I saw some really useful videos on it, and have written my first test. However, said test is failing and I'm not sure why.

I believe I have all the gems I need and I'm reasonably sure that all the configs are done as per the documentation.

But, when I run the feature, it fails on missing content, but I know the content is in the correct view, and I know that the view is being served correctly. I can manually navigate, and it looks as it should, but the cucumber/capybara steps are saying it can't find the content.

For my step definition, I have:

When I visit the homepage
  get root_path
  response.should have_content("Log In")
end

In the application layout, I have the words "Log In" that show when a user is not logged in.

when the feature runs, I get the failure message:

expected there to be content "Log In" in ""

Is there a way to see what the html is that's being rendered by the response inside the test? I tried just doing a puts(response) but that didn't do anything. Any other reason it might be failing that I'm not considering?

Upvotes: 1

Views: 3102

Answers (3)

mandreko
mandreko

Reputation: 1796

In addition to the save_and_open_page functions, I find that I like using the launchy gem a bit more. It seems more cucumber-ish.

If you add to your Gemfile

gem 'launchy'

And of course run

bundle install

You can simply in your cucumber test write:

When ...
Then show me the page
Then I should see ...

The Then show me the page will launch the browser as well. I haven't checked, but I'm guessing it's just sitting on top of the save_and_open_page function, but again, it feels better for me.

Upvotes: 4

Andy Waite
Andy Waite

Reputation: 11096

Use save_and_open_page:

http://technicalpickles.com/posts/debugging-cucumber/

Upvotes: 3

iafonov
iafonov

Reputation: 5192

You have to use visit not get. Moreover it is better to split your step and use standard step When I go to <page_name> (See web_steps.rb and paths.rb)

I suggest you to take a look into rubygems.org project - it has cool set of features and you can use it as an example.

Upvotes: 1

Related Questions