Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy the devise user instance does not get stubbed?
    primarykey
    data
    text
    <p>i have a @user instance that i use for logging a devise user. It's a macro as Devise wiki proposes :</p> <pre><code>module ControllerMacros def login_user before(:each) do @request.env["devise.mapping"] = :user @user = Factory(:user) sign_in @user end end end </code></pre> <p>Generally, i do different things to stub methods, but i don't understand why this stub does not work : (note that @user is indeed logged in, i use it successfully for testing attributes and stuff)</p> <pre><code>@user.stub(:has_tavern_quest?).and_return(true) </code></pre> <p>It seems that the stub works(i checked with @user.has_tavern_quest should true), but i just get back :</p> <pre><code> Failure/Error: flash[:error].should == I18n.t('error.has_quest') expected: "You already have a quest to finish !" got: nil (using ==) </code></pre> <p>The whole controller method is :</p> <pre><code>quest_type = params[:quest_type] @quest_minutes = TavernQuest.get_quest_minutes_from_quest_type(quest_type) flash[:error] = I18n.t('error.invalid_post') and redirect_to tavern_url and return unless [1,2,3,4].include? quest_type.to_i flash[:error] = I18n.t('error.has_quest') and redirect_to tavern_url and return if current_user.has_tavern_quest? flash[:error] = I18n.t('error.no_adv_points') and redirect_to tavern_url and return if current_user.adventure_points &lt; @quest_minutes current_user.reduce_adventure_points(@quest_minutes.to_i) TavernQuest.create(:user_id =&gt; current_user.id, :start_time =&gt; Time.now, :end_time =&gt; Time.now + @quest_minutes.minutes, :duration =&gt; @quest_minutes, :quest_type =&gt; quest_type) redirect_to tavern_url </code></pre> <p>end</p> <p>And the whole spec is :</p> <pre><code> it "should redirect to '/tavern' with an error if user already has a tavern quest" do @user.stub(:has_tavern_quest?).and_return(true) post :create, :quest_type =&gt; 3 flash[:error].should == I18n.t('error.has_quest') response.should redirect_to tavern_url end </code></pre> <p>Anybody knows why and what is the way to make it work ?</p>
    singulars
    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