Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara::Element Not Found

Tags:

capybara

I'm working along with the Rspec book as it develops a 'showtime' rails application, which provides information about films. As far as I can tell, I've copied the code exactly (the book's not that great at letting readers know every step to take), but I'm getting this error.

Unable to find select box "Release Year" (Capybara::ElementNotFound)
      ./features/step_definitions/movie_steps.rb:6:in `/^I create a movie Caddyshack in the Comedy genre$/'

My movie_steps.rb file has this code, which provides users a select box to select the release year, which is the element Capybara can't find.

#---
When /^I create a movie Caddyshack in the Comedy genre$/ do
  visit movies_path
  click_link "Add Movie"
  fill_in "Title", :with => "Caddyshack"
  select "1980", :from => "Release Year"
  check "Comedy"
  click_button "Save"
end

Then /^Caddyshack should be in the Comedy genre$/ do
  visit genres_path
  click_link "Comedy"
  response.should contain("1 movie")
  response.should contain("Caddyshack")
end

In the movies view, I have this code, which is, as far as I can tell, all i need to implement the select box.

<%= form_for @movie do |f| %>
  <%= f.label :title %>
  <%= f.text_field :title %>
  <%= f.label :release_year %>
  <%= f.select :release_year, (1900..2009).to_a.map(&:to_s) %>
  <% @genres.each do |genre| %>
    <label>
      <%=h genre.name %>
      <%= check_box_tag "genres[]", genre.id %>
    </label>
  <% end %>
  <%= f.submit "Save" %>
<% end %>

I'd be grateful for any suggestions you could provide.

like image 677
BrainLikeADullPencil Avatar asked Jun 22 '26 22:06

BrainLikeADullPencil


1 Answers

Try select "1980", :from => "Release year" instead. If you want it to display as "Release Year", then change your label to show as follows:

f.label :release_year, "Release Year"

Rails automatically formats the label for you using the humanize method, but you can change it to anything you like.

like image 137
David Frey Avatar answered Jun 28 '26 23:06

David Frey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!