John Y
John Y

Reputation: 1271

Cucumber/capybara feature always passes regardless of page content

I have the following cucumber scenario:

Background:
  Given the following roles exist:
  | id | name    |
  | 1  | janitor |
  And the following users exist:
  | username | password   | email               | role_ids |
  | janitor  | Cleaning31 | [email protected] | 1        |
  And I am logged in as "janitor" with password "Cleaning31"
  And the following articles exist:
  | id | title       | slug        | content      |
  | 1  | Article One | article-one | Article one. |

Scenario: Seeing link for deleting an article
  When I view the article list
  Then I should see the "Delete" link for article 1

...and the definition for that last step:

Then /^I should (not )?see the "([^"]*)" link (?:in|under|for) article (\d+)$/ do |negation, content, article_id|
  page.should have_selector("\#article_#{article_id}") do |article|
    if negation
      article.should_not have_css('a', text: content)
    else
      article.should have_css('a', text: content)
    end
  end
end

Even if I change the word "Delete" to "this should never work" in either the feature or the view, the feature always passes. In the browser, however, the "Delete" link correctly only appears on articles for users who have the "janitor" role.

Cucumber's "show me the page" and "show me the response" don't seem to be defined, despite a large number of articles suggesting they should be. (My env.rb)

Other feature seem to work as expected. Can anybody spot where I'm going wrong with this?

Upvotes: 0

Views: 604

Answers (1)

socjopata
socjopata

Reputation: 5095

I see no assertions in your test. Try changing article.should_not have_css('a', text: content) to assert article.should_not have_css('a', text: content), and so on.

Edit:

What's the result of?

element = page.find("\#article_#{article_id}")
if negation
      element.should_not have_css('a', text: content)
else
      element.should have_css('a', text: content)
end

Imho you should use find helper and then make assertions on the element you find. I wonder what you have available in the block as "article".

Upvotes: 3

Related Questions