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_trueit 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:in `And I should signin'' But I signed in! Why? What''s the way to test authentication system from scratch? -- Posted via http://www.ruby-forum.com/.
On Wed, Nov 23, 2011 at 3:10 PM, Alex Whiteland <lists at ruby-forum.com> wrote:> I don''t know where to put this post,Here: http://groups.google.com/group/cukes> 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:in `And I should signin'' > > But I signed in! Why? What''s the way to test authentication system from > scratch? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
> 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. Patrick J. Collins http://collinatorstudios.com
Aslak, but if I haven''t Google Account? -- Posted via http://www.ruby-forum.com/.
On Wed, Nov 23, 2011 at 4:19 PM, Alex Whiteland <lists at ruby-forum.com> wrote:> Aslak, but if I haven''t Google Account? >You don''t need one. Click "About this group", and you''ll see the group''s email address. Your first message will be moderated. Aslak> -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
> that is added to cucumber''s world does not have access to your > application > controller''s @current_user variable.So, I understand this. But how I can avoid this defect? If I paste def is_admin? into application_controller near current_user method, I wouldn''t can World(ApplicationController). If I copy current_user code to sessions_helper, then session[:user_id] wouldn''t work. -- Posted via http://www.ruby-forum.com/.
On Wed, Nov 23, 2011 at 5:55 PM, Alex Whiteland <lists at ruby-forum.com> wrote:>> that is added to cucumber''s world does not have access to your >> application >> controller''s @current_user variable. > > So, I understand this. But how I can avoid this defect? > > If I paste def is_admin? into application_controller near current_user > method, I wouldn''t can World(ApplicationController). If I copy > current_user ?code to sessions_helper, then session[:user_id] wouldn''t > work. >Please don''t have this discussion here. You''re on the wrong list. Use the Cucumber list.> -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Aslak, I send a message to group email, but I haven''t answer yet. -- Posted via http://www.ruby-forum.com/.
On Thu, Nov 24, 2011 at 11:12 AM, Alex Whiteland <lists at ruby-forum.com> wrote:> Aslak, I send a message to group email, but I haven''t answer yet. >What email did you send to? We haven''t received anything from you. I''m assuming you''re using a regular mail client?> -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
> What email did you send to?cukes at googlegroups.com> I''m assuming you''re using a regular mail client?I work from browser. I sent to you from awhiteland.37.com (first . replace to @) -- Posted via http://www.ruby-forum.com/.
bump! I sent letter 3 day ago. No email answer, no new theme in group, no new message here. But new message in group exists. Why? -- Posted via http://www.ruby-forum.com/.
On Nov 28, 2011, at 4:46, Alex Whiteland <lists at ruby-forum.com> wrote:> bump! > > I sent letter 3 day ago. > > No email answer, no new theme in group, no new message here. But new > message in group exists. Why? >I haven''t seen any messages from you to cukes at googlegroups.com Do you have a link to it?> -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
wtf? maybe I post an initiate letter here, and then find a way to write you?> Started hereHi! 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_trueit 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:in `And I should signin'' But I signed in! Why? What''s the way to test authentication system from scratch?> that is added to cucumber''s world does not have access to your > application > controller''s @current_user variable.So, I understand this. But how I can avoid this defect? If I paste def is_admin? into application_controller near current_user method, I wouldn''t can World(ApplicationController). If I copy current_user code to sessions_helper, then session[:user_id] wouldn''t work. Regards, Alex Whiteland> end-- Posted via http://www.ruby-forum.com/.
I sent copy of my issue to cukes at googlegroups.com from awhiteland at hushmail.com -- Posted via http://www.ruby-forum.com/.
On Mon, Nov 28, 2011 at 9:38 AM, Alex Whiteland <lists at ruby-forum.com> wrote:> wtf? > > maybe I post an initiate letter here, and then find a way to write you? > >> Started here > Hi! > > 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:in `And I should signin'' > > But I signed in! Why? What''s the way to test authentication system from > scratch? > >> that is added to cucumber''s world does not have access to your >> application >> controller''s @current_user variable. > > So, I understand this. But how I can avoid this defect?It is not a defect. It''s how cukes work. They wrap Rails integration tests, which don''t give you direct access to controllers or sessions. Your options are: 1. actually log in (i.e. create a user, go to the login screen and log in). You can wrap this in a single step definition like "Given I am logged in as ''admin''", but you still have to go through the app within the step definition. 2. This only works for in-memory scenarios (i.e. it doesn''t work in-browser when the app is running in a separate process) - you _can_ stub the controller using any_instance: FooController.any_instance.stub(:current_user).and_return(user) HTH, David> > If I paste def is_admin? into application_controller near current_user > method, I wouldn''t can World(ApplicationController). If I copy > current_user ?code to sessions_helper, then session[:user_id] wouldn''t > work. > > Regards, Alex Whiteland >> end > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
> 1. actually log in (i.e. create a user, go to the login screen and log > in). You can wrap this in a single step definition like "Given I am > logged in as ''admin''", but you still have to go through the app within > the step definition.I do this. Here is example: Scenario: guest becomes a user Given I am guest When I go to the signup_path And puts signup info Then new user should be created And I should signin> Smth.Given /^I am guest$/ do get_me_the_cookies.should eq([]) end When /^I go to the signup_path$/ do visit signup_path end When /^puts signup info$/ do fill_in "user_username", :with => "frankpopp" fill_in "user_first", :with => "Frank" fill_in "user_second", :with => "Popp" fill_in "user_password", :with => "123456" fill_in "user_password_confirmation", :with => "123456" click_button "Sign up!" end Then /^new user should be created$/ do page.should have_content("New user added: frankpopp") end Then /^I should signin$/ do is_user?.should be_true end> in users_controller.rb:def create @user = User.new(params[:user]) if @user.save session[:user_id] = @user.id # This create a session flash[:success] = "New user added: " + @user.username flash[:notice] = "His password is: " + @user.password if is_admin? redirect_to @user else end end -- Posted via http://www.ruby-forum.com/.
On Nov 28, 2011, at 10:07 PM, Alex Whiteland wrote:>> 1. actually log in (i.e. create a user, go to the login screen and log >> in). You can wrap this in a single step definition like "Given I am >> logged in as ''admin''", but you still have to go through the app within >> the step definition. > I do this. Here is example: > > Scenario: guest becomes a user > Given I am guest > When I go to the signup_path > And puts signup info > Then new user should be created > And I should signin > >> Smth. > > Given /^I am guest$/ do > get_me_the_cookies.should eq([]) > end^^ Givens, by definition, are given; to be taken for granted. They should not have expectations in them. If you feel the need to have an expectation in them, it suggests that there is another sceneario missing.> When /^I go to the signup_path$/ do > visit signup_path > end > > When /^puts signup info$/ do > fill_in "user_username", :with => "frankpopp" > fill_in "user_first", :with => "Frank" > fill_in "user_second", :with => "Popp" > fill_in "user_password", :with => "123456" > fill_in "user_password_confirmation", :with => "123456" > click_button "Sign up!" > end > > Then /^new user should be created$/ do > page.should have_content("New user added: frankpopp") > endThis doesn''t tell you that the new user actually exists. Here I''d recommend going to the database: Then /^new user should be created$/ do User.find_by_username("frankpopp").should_not be_nil end> Then /^I should signin$/ do > is_user?.should be_true > endYour email earlier this thread has an "is_admin?" method, so I''ll assume "is_user?" works the same way: def is_admin? @current_user && @current_user.id != 1 end The problem is that @current_user is an instance variable inside the controller. You can''t access it from a scenario. Usually I just use something something on the page to identify that "frankpopp" is signed in.>> in users_controller.rb: > def create > @user = User.new(params[:user]) > if @user.save > session[:user_id] = @user.id # This create a session > flash[:success] = "New user added: " + @user.username > flash[:notice] = "His password is: " + @user.password if is_admin? > redirect_to @user > else > > end > endHTH, David
On Nov 29, 2011, at 4:24 AM, David Chelimsky wrote:> > On Nov 28, 2011, at 10:07 PM, Alex Whiteland wrote: > >>> 1. actually log in (i.e. create a user, go to the login screen and log >>> in). You can wrap this in a single step definition like "Given I am >>> logged in as ''admin''", but you still have to go through the app within >>> the step definition. >> I do this. Here is example: >> >> Scenario: guest becomes a user >> Given I am guest >> When I go to the signup_path >> And puts signup info >> Then new user should be created >> And I should signin >> >>> Smth. >> >> Given /^I am guest$/ do >> get_me_the_cookies.should eq([]) >> end > > ^^ Givens, by definition, are given; to be taken for granted. They should not have expectations in them. If you feel the need to have an expectation in them, it suggests that there is another sceneario missing. > >> When /^I go to the signup_path$/ do >> visit signup_path >> end >> >> When /^puts signup info$/ do >> fill_in "user_username", :with => "frankpopp" >> fill_in "user_first", :with => "Frank" >> fill_in "user_second", :with => "Popp" >> fill_in "user_password", :with => "123456" >> fill_in "user_password_confirmation", :with => "123456" >> click_button "Sign up!" >> end >> >> Then /^new user should be created$/ do >> page.should have_content("New user added: frankpopp") >> end > > This doesn''t tell you that the new user actually exists. Here I''d recommend going to the database: > > Then /^new user should be created$/ do > User.find_by_username("frankpopp").should_not be_nil > end > >> Then /^I should signin$/ do >> is_user?.should be_true >> end > > Your email earlier this thread has an "is_admin?" method, so I''ll assume "is_user?" works the same way: > > def is_admin?^^ That should have been is_user?> @current_user && @current_user.id != 1 > end > > The problem is that @current_user is an instance variable inside the controller. You can''t access it from a scenario. Usually I just use something something on the page to identify that "frankpopp" is signed in.Also, if you want to specify that frankpopp is an admin, you can either check the database via the model (i.e. User.find_by_username("frankpopp").should be_admin or some such), or, again, look for some identifying feature on the page - maybe a link that only admins can see.>>> in users_controller.rb: >> def create >> @user = User.new(params[:user]) >> if @user.save >> session[:user_id] = @user.id # This create a session >> flash[:success] = "New user added: " + @user.username >> flash[:notice] = "His password is: " + @user.password if is_admin? >> redirect_to @user >> else >> >> end >> end > > HTH, > DavidBTW - while I do want to see you get the help you need, this conversation is noise for many rspec-users readers, so if you have all you need, please wait until you get your membership on the Cucumber list sorted out before continuing it. If things are still not working for you, however, please feel free to continue the conversation until this particular issue is resolved for you. Cheers, David
On 28 November 2011 15:48, Alex Whiteland <lists at ruby-forum.com> wrote:> I sent copy of my issue to cukes at googlegroups.com from > awhiteland at hushmail.com > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >I''m a moderator on the Cukes list. There are no outstanding messages awaiting moderation. I suggest you try again. Send your message to cukes at googlegroups.com All best Andrew -- ------------------------ Andrew Premdas blog.andrew.premdas.org
Hi, Andrew. I resent msg now. -- Posted via http://www.ruby-forum.com/.
On 2 December 2011 07:49, Alex Whiteland <lists at ruby-forum.com> wrote:> Hi, Andrew. > > I resent msg now. >You are not in banned list or members list and there is no message pending. I suspect you are doing something wrong or possibly your email address is not liked by google. Perhaps you could try another account? All best Andrew> -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-- ------------------------ Andrew Premdas blog.andrew.premdas.org
hmm... I changed 2 servers to friend with google. wtf? first - 37.com, second - hushmail.com Maybe, google think it is spam and sends to it folder. Can yo find my letters in it? -- Posted via http://www.ruby-forum.com/.
This is an rspec mailing list. On Wed, Dec 7, 2011 at 12:48, Alex Whiteland <lists at ruby-forum.com> wrote:> hmm... > > I changed 2 servers to friend with google. wtf? > > first - 37.com, > second - hushmail.com > > Maybe, google think it is spam and sends to it folder. Can yo find my > letters in it? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- *"In matters of style, swim with the current; in matters of principle, stand like a rock." Thomas Jefferson * -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20111207/d91e10bf/attachment.html>