Hi, If I want my functional tests to bypass the built in Rails HTTP authentication, how would I do that? Would I use something like FlexMock to stub out the :before_filter for my controller? Could someone please provide an example, because I''m not really understanding the basics for this scenario. Cheers, Peter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I''m assuming that the lack of replies suggests that this is the wrong way to go about. Should I provide some login details in my tests or what would you suggest? // Peter 2010/10/12 Peter Hultgren <peter.evjan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Hi, > > If I want my functional tests to bypass the built in Rails HTTP > authentication, how would I do that? > > Would I use something like FlexMock to stub out the :before_filter for > my controller? Could someone please provide an example, because I''m > not really understanding the basics for this scenario. > > Cheers, > Peter > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Peter Hultgren wrote in post #949752:> Hi, > > If I want my functional tests(which you should replace with Cucumber scenarios)> to bypass the built in Rails HTTP > authentication, how would I do that?Why do you want to do that? What are you trying to achieve?> > Would I use something like FlexMock to stub out the :before_filter for > my controller? Could someone please provide an example, because I''m > not really understanding the basics for this scenario.It''s hard to understand your use case, and without your ultimate goal, it''s very difficult to give useful suggestions.> > Cheers, > PeterBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ah, so the question was unclear. Let me try to rephrase it: I want to write a test against my controller to make sure that the actions respond as they should, but since I have HTTP authentication turned on I get failures like this: "response to be a <:success>, but was <401>" So the test runs just fine with authentication turned off, but fails when turned on. What should I do to get past this and be able to test the logic of my controller? // Peter 2010/10/13 Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> Peter Hultgren wrote in post #949752: >> Hi, >> >> If I want my functional tests > > (which you should replace with Cucumber scenarios) > >> to bypass the built in Rails HTTP >> authentication, how would I do that? > > Why do you want to do that? What are you trying to achieve? > >> >> Would I use something like FlexMock to stub out the :before_filter for >> my controller? Could someone please provide an example, because I''m >> not really understanding the basics for this scenario. > > It''s hard to understand your use case, and without your ultimate goal, > it''s very difficult to give useful suggestions. > >> >> Cheers, >> Peter > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Oct-13 21:30 UTC
Re: Re: Functional testing and HTTP authentication
Please quote when replying. Peter Hultgren wrote in post #949955:> Ah, so the question was unclear. Let me try to rephrase it: > > I want to write a test against my controller to make sure that the > actions respond as they should, but since I have HTTP authentication > turned on I get failures like this: > "response to be a <:success>, but was <401>" > > So the test runs just fine with authentication turned off, but fails > when turned on. What should I do to get past this and be able to test > the logic of my controller?Have your test code log in at the beginning of your tests. With controller tests, that probably goes in a before block; with Cucumber stories (which I highly recommend using instead), you actually want that in your scenarios themselves (or your scenario background), in order to better document and model the workflow.> > // Peter > > 2010/10/13 Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Oct-13 21:33 UTC
Re: Re: Functional testing and HTTP authentication
Marnen Laibow-Koser wrote in post #949979:> Please quote when replying. > > Peter Hultgren wrote in post #949955: >> Ah, so the question was unclear. Let me try to rephrase it: >> >> I want to write a test against my controller to make sure that the >> actions respond as they should, but since I have HTTP authentication >> turned on I get failures like this: >> "response to be a <:success>, but was <401>" >> >> So the test runs just fine with authentication turned off, but fails >> when turned on. What should I do to get past this and be able to test >> the logic of my controller? > > Have your test code log in at the beginning of your tests. With > controller tests, that probably goes in a before block;On second thought, in this case, you might want to stub your before_filter. Or you might not. The rest of my advice stands. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Peter Hultgren wrote in post #949955:> Ah, so the question was unclear. Let me try to rephrase it: > > I want to write a test against my controller to make sure that the > actions respond as they should, but since I have HTTP authentication > turned on I get failures like this: > "response to be a <:success>, but was <401>" > > So the test runs just fine with authentication turned off, but fails > when turned on. What should I do to get past this and be able to test > the logic of my controller?With RSpec and FactoryGirl I do something like: describe "authenticated" do before(:each) do login_as(Factory(:user)) end it "does something as a logged in user" do ... end end /lib/AuthenticatedTestHelper -------------------------- def login_as(user) @request.session[:user_id] = user ? (user.is_a?(User) ? user.id : users(user).id) : nil end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Oct-14 21:13 UTC
Re: Re: Functional testing and HTTP authentication
Robert Walker wrote in post #950276:> Peter Hultgren wrote in post #949955: >> Ah, so the question was unclear. Let me try to rephrase it: >> >> I want to write a test against my controller to make sure that the >> actions respond as they should, but since I have HTTP authentication >> turned on I get failures like this: >> "response to be a <:success>, but was <401>" >> >> So the test runs just fine with authentication turned off, but fails >> when turned on. What should I do to get past this and be able to test >> the logic of my controller? > > With RSpec and FactoryGirl I do something like: > > describe "authenticated" do > before(:each) do > login_as(Factory(:user)) > end > > it "does something as a logged in user" do > ... > end > endThat works, to be cure, but why are you using RSpec on your controllers? That''s a job for Cucumber. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser wrote in post #950279:> That works, to be cure, but why are you using RSpec on your controllers? > That''s a job for Cucumber.Mostly because I pulled this from an older project where I wasn''t yet using Cucumber. I was just learning RSpec at the time. I might do things differently today. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.