Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are testing has_basket_items? action in ApplicationHelper, which check a specfic basket with a basket_id in the baskets table, so you should have some basket objects in your test which you can create using <a href="https://github.com/thoughtbot/factory_girl" rel="nofollow">Factory_Girl</a> gem.</p> <p>Hers's an example :-</p> <pre><code>basket1 = Factory(:basket, :name =&gt; 'basket_1') basket2 = Factory(:basket, :name =&gt; 'basket_2') </code></pre> <p>You can get more details on How to use factory_girl from this screen cast <a href="http://railscasts.com/episodes/158-factories-not-fixtures" rel="nofollow">http://railscasts.com/episodes/158-factories-not-fixtures</a></p> <p>It will create a Factory object in your test database. So, basically you can create some factory objects and then set a basket_id in session to check for its existence like this :</p> <pre><code>session[:basket_id] = basket1.id </code></pre> <p>So, your test should be like this :- </p> <pre><code>require 'spec_helper' describe ApplicationHelper do describe 'has_basket_items?' do describe 'with no basket' do it "should return false" do basket1 = Factory(:basket, :name =&gt; 'basket_1') basket2 = Factory(:basket, :name =&gt; 'basket_2') session[:basket_id] = 1234 # a random basket_id helper.has_basket_items?.should be_false end end end end </code></pre> <p>Alternatively, you can check for a basket_id which is being created by factory_girl to be_true by using :</p> <pre><code>session[:basket_id] = basket1.id helper.has_basket_items?.should be_true </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.
    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