samedi 6 juin 2015

rspec controller instance variable not seen

new_controller_spec.rb

require 'spec_helper'

describe NewController do
  before do
    allow(controller).to receive(:current_user) { nil }
  end

  describe 'routing' do
    it 'GET /become_a_driver' do
      {:get => '/become_a_driver'}.should route_to(:controller => 'new', :action => 'become_a_driver')
    end

    it 'GET /franchise_opportunities' do
      {:get => '/franchise_opportunities'}.should route_to(:controller => 'new', :action => 'franchise_opportunities')
    end
  end

  describe 'actions' do

    before do
      FactoryGirl.create(:domain, :franchises => [FactoryGirl.create(:franchise)])
    end

    describe 'GET /become_a_driver' do
      it 'renders v3/become_a_driver' do
        get :become_a_driver
        response.should render_template('v3/become_a_driver')
      end
    end

    describe 'GET /franchise_opportunities' do
      it 'renders new/franchise_opportunities' do
        get :franchise_opportunities
        response.should render_template('new/franchise_opportunities')
      end

      it 'renders new/franchise_opportunities' do
        get :franchise_opportunities
        response.should render_template('new/franchise_opportunities')
      end
    end

    describe 'POST /franchise_opportunities' do
      it 'renders new/franchise_opportunities when errors' do
        post :franchise_opportunities, name: 'Vasya'
        response.should render_template('new/franchise_opportunities')
      end

      it 'renders v3/franchise_opportunities when domain id 5' do
        domain = Domain.new
        domain.stub(:mrdeliverycom?) { true }
        controller.instance_variable_set(:@domain, domain)

        post :franchise_opportunities, name: 'Vasya'
        response.should render_template('v3/franchise_opportunities')
      end
    end
  end
end

new_controller.rb

# -*- encoding : utf-8 -*-
class NewController < ApplicationController
 def franchise_opportunities

    t = Logger.new(STDOUT)
    t.debug '=============================================='
    t.debug @domain
    t.debug @domain.mrdeliverycom?
    t.debug '=============================================='

    render :layout=>'v3', :template=>'v3/franchise_opportunities' and return if @domain && @domain.mrdeliverycom?

    @errors={}
    @post = params.clone
    ...

 end
end

Log

==============================================
nil
nil
==============================================

Seems @domain variable is not instantiated in controller.

Aucun commentaire:

Enregistrer un commentaire