Addy
Addy

Reputation: 1851

cucumber should see button

I have a form that has this

<%= submit_tag 'Search Event' %>

and a cucumber step that says

And I should see "Search Event"

but this step fails.. why is that?

Here is the error i get

expected #has_content?("Search Event") to return true, got false (RSpec::Expectations::ExpectationNotMetError)

Upvotes: 1

Views: 2202

Answers (3)

This work in positive:

Then /^I should see "([^"]*)" button/ do |name|
  should have_button name
end

in negative:

Then /^I should not see "([^"]*)" button/ do |name|
  should have_no_button name
end

Upvotes: 1

morgoth
morgoth

Reputation: 1451

Write your own step, i.e. using capybara (rspec as well):

Then /^I should see "([^"]*)" button/ do |name|
  find_button(name).should_not be_nil
end

Upvotes: 13

Jeremy Weiskotten
Jeremy Weiskotten

Reputation: 978

I think this doesn't work because the button label is not text content -- it's the value attribute of the submit button.

Upvotes: 1

Related Questions