2
votes

I don't know where to put this post, but theme of this more similar to my issue.

I have trite signin system, like this:

ApplicationController: include SessionsHelper

private

helper_method :current_user

def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end

SessionsHelper: def is_admin? @current_user && @current_user.id == 1 end

features/support/env.rb: World(SessionsHelper)

So, if I test

is_admin?.should be_true

it returns:

expected nil to be true (RSpec::Expectations::ExpectationNotMetError) ./features/step_definitions/users/add_user.rb:23:in /^I should signin$/' features/users/add_user.feature:13:inAnd I should signin'

But I signed in! Why? What's the way to test authentication system from scratch?

1

1 Answers

1
votes

I don't know where to put this post, but theme of this more similar to my issue. The cucumber mailing list is: http://groups.google.com/group/cukes

But I can tell you that your problem is a scope issue. Your is_admin? method that is added to cucumber's world does not have access to your application controller's @current_user variable.