I have two rails resources: notes & technologies.
Note Model:
class Note < ActiveRecord::Base
belongs_to :technology
end
Tecnology Model:
class Technology < ActiveRecord::Base
has_many :notes
end
I want to use the following Capybara steps:
Scenario: Viewing notes and their technology association
Given there are the following notes:
| subject |
| recursive functions |
And the note "recursive functions" has the technology "JavaScript"
And I am on the homepage
Then I should see "recursive functions"
And I should see "JavaScript"
The step I use for the line:
And the note "recursive functions" has the technology "JavaScript"
Is (I suspect the issue is in the following):
Given /^the note "(.*?)" has the technology "(.*?)"$/ do |note, tech|
@note = Note.find_by_subject!(note)
@note.technology = Technology.find_or_create_by_name(tech)
end
I want this to find_or_create the given Technology object’s name (name is a parameter of the Technology object) and create the association so that the note belongs to the technology.
Then, the last step:
And I should see "JavaScript"
Is to verify that note.technology.name is displaying next to each note instance on Note#index
<% @notes.each do |note| %>
<li>
<%= link_to note.subject, note %>
<% if note.technology %>
| Tech: <%= note.technology.name %>
<% end %>
</li>
<% end %>
When I run this Cucumber feature the steps pass until the last, And I should see “JavaScript”, with the error:
expect there to be content "JavaScript" in "Note Index Page"
recursive functions \n \n recursive functions \n \n (RSpec:Expectations::ExpectactionNotMetError
./features/step_definitions/web_steps.rb:107 in '/^(?:|I )should see "([^"]*)"$/'
features\viewing_notes.feature:20:in 'And I should see "JavsScript"'
I know that the association is working because creating this association with a form works (and displays @note.technology.name on Note#index). The issue seems to be with my step definition. Is there a better way to test this to see what’s happening? Maybe writing an Rspec spec? Thanks for taking the time to help.
(Possibly relevant:)
gem 'rails', '3.0.0'
group :test do
gem 'rspec-rails', '2.0'
gem 'factory_girl', '2.6.4'
end
group :cucumber do
gem 'cucumber-rails', '1.0.6'
gem 'capybara'
end
Quick answer: