Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 & Cucumber - step definition for creating an association
    primarykey
    data
    text
    <p>I have two rails resources: notes &amp; technologies.</p> <p><strong>Note Model:</strong></p> <pre><code>class Note &lt; ActiveRecord::Base belongs_to :technology end </code></pre> <p><strong>Tecnology Model:</strong></p> <pre><code>class Technology &lt; ActiveRecord::Base has_many :notes end </code></pre> <p><strong>I want to use the following Capybara steps:</strong></p> <pre><code>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" </code></pre> <p>The step I use for the line:</p> <pre><code> And the note "recursive functions" has the technology "JavaScript" </code></pre> <p>Is (<strong>I suspect the issue is in the following</strong>): </p> <pre><code>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 </code></pre> <p>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.</p> <p>Then, the last step:</p> <pre><code>And I should see "JavaScript" </code></pre> <p>Is to verify that note.technology.name is displaying next to each note instance on Note#index</p> <pre><code> &lt;% @notes.each do |note| %&gt; &lt;li&gt; &lt;%= link_to note.subject, note %&gt; &lt;% if note.technology %&gt; | Tech: &lt;%= note.technology.name %&gt; &lt;% end %&gt; &lt;/li&gt; &lt;% end %&gt; </code></pre> <p>When I run this Cucumber feature the steps pass until the last, <em>And I should see "JavaScript"</em>, with the error:</p> <pre><code>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"' </code></pre> <p>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.</p> <p>(Possibly relevant:)</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload