Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I came up with a solution, but I am not sure of its validity in terms of how clean it is. I ended up using Factory Girl (installed the gem). I kept my scenario the same. </p> <p><br> Under <b>features/step_definitions</b> I created <b>posting_steps.rb</b></p> <pre><code>Given /^there is a posting$/ do Factory(:posting) end </code></pre> <p><br> Under <b>features/support</b> I created a file <b>factories.rb</b> with the following inside:</p> <pre><code>Factory.define :posting do |f| f.association :user f.title 'blah' f.location 'Some place' end </code></pre> <p>In my <b>paths.rb</b> I used</p> <pre><code>when /the edit posting page/ edit_posting_path(Posting.first) </code></pre> <p><br><br> How it works <i>(or at least how I think it works)</i> is that as <br></p> <pre><code>Given there is a posting </code></pre> <p>is executed, the <b>posting_step.rb</b> is invoked (<i><b>Factory(:posting) is basically Factory.create(:posting)</b></i>), which in turn uses the factory definition I created in <b>factories.rb</b>. This leads to an instance of a posting being created. <br><br>Then in my <b>paths.rb</b> <br></p> <pre><code>when /the edit posting page/ edit_posting_path(Posting.first) </code></pre> <p>gets passed the id from the instance, to ultimately get a path that could resemble /posting/1/edit , and the test continues on its way! <br><br> If there are any corrections to be made, please let me know as I am just learning the ropes. Hopefully this will help other newbies out there!</p>
 

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