4
votes

I'm testing rails app with the Cucumber and Capybara/rack_test. I have following step definition:

Then /^I should see '([^']*)'$/ do |content|
  visit about_path
  response.should have_content(content)
end

where about_path maps to /about.

Every time my story fails with the message

Feature: Some Great Feature

  So that I can blah-blah
  As a Blah-blah
  I want blah-blah

  Scenario: Show project label on about page # features/about.feature:7
    Given I'm on '/about' page               # features/step_definitions/about_steps.rb:1
    Then I should see 'About'            # features/step_definitions/about_steps.rb:5
      expected there to be content "About" in "" (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/about_steps.rb:7:in `/^I should see '([^']*)'$/'
      features/about.feature:9:in `Then I should see 'About''

Failing Scenarios:
cucumber features/about.feature:7 # Scenario: Show project label on about page

1 scenario (1 failed)
2 steps (1 failed, 1 passed)

Note that actual content is empty. It is empty with every path I've tried.

It is strange because rspecs passes.

Is there anything I could try? Tell me if you need additional information.

1
Does it work correctly in a browser?dpassage
Yes, when I run test server I can navigate to localhost/about and see the correct page.lambdas
How about debugging it with save_and_open_page?fkreusch
@fkreusch, I've inserted save_and_open_page just after visit, browser shows page without styling, but it definitely not empty.lambdas
Than it seems like a problem with the matcher/content you are passing in. Can you paste the block of the actual html that you expect to match and the value you are trying to match against?fkreusch

1 Answers

0
votes

You shouldn't use response to get to the content. Try with page instead.