Reputation: 17482
DISCLAIMER: I am still a Rails/Cucumber newbie but I am trying to learn. I am still using the "web_steps" for Cucumber while I work through the RailsInAction book and I have experimented with writing my own steps. I understand why they were taken out and I will get there.
In one of my Cucumber Scenarios I am populating some data and trying to use that data to populate a dropdown. The data is definitely being inserted, I know this because I wrote a step to test to see if the data is in fact there and it is.
When then DropDown is suppose to populated and I try "select" from that DropDown I get the error "*cannot select option, no option with text 'Steven' in select box 'result_winner' (Capybara::ElementNotFound)*"
I am sure I am missing something basic but I have lost about an hour to this now and I just need some help.
The tests:
When I follow "Record new Result"
And the users "Steven, Joshua" exist
And I select "Steven" from "result_winner"
The test steps:
When /^the users "([^"]*)" exist$/ do |playerNames|
@names = playerNames.scan(/[\w']+/)
for name in @names
@newPlayer = Player.new
@newPlayer.name = name
@newPlayer.save
end
end
Then the view code in the _form.html.erb:
<p>
<%= f.label :winner %>
<%= select("result", "winner", @players.map {|p| [p.name, p.id]}) %>
</p>
The Controller:
def new
@result = Result.new
@players = Player.find(:all)
end
If I manually populate the development database with names and load it up in the browser, the dropdowns have data populated in them and work perfectly. I am pretty sure I am misunderstanding when/where test data is visible, or how to test for and select data from a dropdown.
Any help would be greatly appreciated.
Upvotes: 2
Views: 1170
Reputation: 25
Your "the users "Steven, Joshua" exist" should be in a Given step.
It describes a state before an action is done.
Given the users "Steven, Joshua" exist
When I follow "Record new Result"
And I select "Steven" from "result_winner"
Upvotes: 0
Reputation: 11705
It looks to me like a simple problem with the step sequence. You're visiting the page, and then populating the database, but the page doesn't get reloaded to take account of the new database values. If you swap the order of the first 2 steps around, I expect that would fix it.
To be clear, cucumber will literally step through your scenario one line at a time:
Upvotes: 3