ruby on rails 4 - Rspec controller tests with chaining method calls -



ruby on rails 4 - Rspec controller tests with chaining method calls -

my controller looks this:

class="lang-rb prettyprint-override">def index params[:page]||1 @stories = story.all.page(params[:page]).per(5) end

when seek write controller tests chaining line through using rspec, can't seem tests pass.

my controller_spec looks like:

class="lang-rb prettyprint-override">describe '#index' let(:story) {double(story)} before allow(story).to receive(:all).and_return(story) allow(story).to receive(:page).and_return(story) allow(story).to receive(:per).and_return(story) :index end context 'when user not logged in' 'should page 1' expect(story).to receive(:page).with(1) end 'should 5 stories' expect(story).to receive(:per).with(5) end end end

what illustration test write such controller?

you should set expect(story).to receive(:page).with(1) before calling get :index

move get :index before block it block:

it 'should page 1' expect(story).to receive(:page).with(1) :index end

ps , looks missed = in controller action

params[:page] ||= 1

ruby-on-rails-4 rspec rspec3

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -