← Back to Upcase

Monban - how can I test sign in?


(Olga Grabek) #1

In Intermediate Rails Workshop we are using Monban gem to authentication. I’d like to write rspec test for DashboardsController to test method show:

class DashboardsController < ApplicationController

  def show
    @shout = Shout.new
    @shouts = current_user.shouts
  end

end

and my test

require ‘spec_helper’

describe DashboardsController do

  describe 'GET #show' do
    it 'assigns new shout instance to shout variable' do
      user = create(:user)
      sign_in(user)
      get :show
      expect(assigns(:shout)).to be_a_new(Shout)
    end

    it 'assigns all shouts of sign_in user to shouts variable' do
      user = create(:user)
      sign_in(user)
      get :show
      expect(assigns(:shouts)).to eq user.shouts
    end
  end

end

It obviously doesn’t work because sign_in method is undefined. So how can I log in user in rspec test with Monban?


(Erik Guzman) #2

Try including the Monban helper in the spec_helper:
config.include Monban::ControllerHelpers, :type => :controller

This is the kind of thing you have to do for testing devise so this could work.


(Olga Grabek) #3

Thank you! That work :slight_smile: Why I have to add this hash as an argument: :type => :controller ? It means that these are controller methods ?


(Olga Grabek) #4

Strange but today this test doesn’t work :frowning: I get this error:

/Users/ograbek/.rvm/gems/ruby-1.9.3-p392@shouter/gems/monban-0.0.6/lib/monban/controller_helpers.rb:12:in `block in <module:ControllerHelpers>': undefined method `helper_method' for #<Class:0x007ff9b1c0ab40> (NoMethodError)

I didn’t change anything.


(Matthew Mongeau) #5

Can you post the failing test?


(Travis Chase) #6

This what I am seeing:

/home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/monban-0.0.7/lib/monban/controller_helpers.rb:12:in block in <module:ControllerHelpers>': undefined methodhelper_method’ for #Class:0x007f3e709cd208 (NoMethodError)
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/concern.rb:114:in class_eval' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/concern.rb:114:inappend_features’
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:860:in include' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:860:insafe_include’
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:854:in block in configure_group' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:852:ineach’
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:852:in configure_group' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/world.rb:46:inconfigure_group’
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:302:in set_it_up' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:245:insubclass’
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:232:in describe' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/dsl.rb:18:indescribe’
from /opt/kyruus/providermatch_beta/spec/controllers/case_controller_spec.rb:3:in <top (required)>' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:inload’
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in block in load_spec_files' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:ineach’
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in load_spec_files' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:22:inrun’
from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in run' from /home/vagrant/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:inblock in autorun’