Skip to content

Instantly share code, notes, and snippets.

@phillipkoebbe
Created December 31, 2009 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipkoebbe/266873 to your computer and use it in GitHub Desktop.
Save phillipkoebbe/266873 to your computer and use it in GitHub Desktop.
module ControllerMacros
def should_set_session(key, options = {})
it "should set session[:#{key}]" do
value = get_value_from_options(options)
if value
session[key].should == value
else
session[key].should_not be_nil
end
end
end
private
def get_value_from_options(options)
value = nil
if options.has_key?(:with)
value = options[:with]
if value.is_a?(Symbol)
value = self.instance_variable_get("@#{value}")
value = value.send(options[:method]) if options.has_key?(:method)
end
end
value
end
end
NoMethodError in 'SessionsController login POST request successful administrator should set session[:user_id]'
undefined method `get_value_from_options' for #<Spec::Rails::Example::ControllerExampleGroup::Subclass_1::Subclass_2::Subclass_2::Subclass_1::Subclass_1:0x1033dc828>
describe 'login' do
context 'POST request' do
context 'successful' do
context 'administrator' do
before :each do
@user = stub_user(user_hash)
User.should_receive(:authenticate).and_return([@user.id, Messages::LOGIN_SUCCESSFUL])
User.should_receive(:find_by_id).and_return(@user)
@user.should_receive(:is_administrator?).and_return(true)
do_post(:login, {:email => @user.email, :password => @user.password})
end
should_set_session(:user_id, :with => :user, :method => :id)
end # context 'administrator'
end # context 'successful'
end # context 'POST request'
end # describe 'login'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment