Hi all, Have been following: http://www.tomtenthij.co.uk/2008/1/25/rspec-plain-text-story-runner-on-a-fresh-rails-app ..as an introduction into the story runner. It shows how to get a couple of scenarios going to test the restful_authenticated plugin from plain text stories. I thought I'd go completely bonkers and try and add a story of my own :) Scenario: Registered user logs in Given a username 'jdoe' And a password 'letmein' And an existing user with these credentials When the user logs in with username and password Then should redirect to '/' And I added these steps to try and make this pass: Given "an existing user with these credentials" do @user = User.new({ :login => @username, :password => @password, :password_confirmation => @password, :email => "jdoe@test.comm" }) @user.save User.find_by_login(@username).should_not be_nil end When "the user logs in with username and password" do post "/sessions/create", :user => { :login => @username, :password => @password } end Then "should redirect to '$path'" do |path| response.should redirect_to(path) end However, I'm getting a Spec::Expectations::ExpectationNotMetError: expected redirect to "/", got no redirect So the user is definitely being created in the test database, but the login doesn't seem to work, or to do the redirect. I must be doing something silly. If anyone could point me in the right direction, I'd be very grateful. Thanks very much, Steven
on 28.04.2008 17:36
on 28.04.2008 18:12
On Mon, Apr 28, 2008 at 8:31 AM, steven shingler <shingler@gmail.com> wrote: > However, I'm getting a > Spec::Expectations::ExpectationNotMetError: expected redirect to "/", > got no redirect Often when this happens, it's because an error occurs in the request. You can tail test.log to see if there are any exceptions being thrown. My initial guess is that your request needs to be post "/sessions" instead of post "/sessions/create" Pat
on 28.04.2008 21:52
Assuming there's nothing helpful in test.log.. Adding 'debugger' to the misfiring steps may help troubleshoot this.. You'll prolly need to add the following to your helper.rb first. require 'rubygems' require 'ruby-debug' Re-run the story and it should stop at the debugger. Between manually submitting requests and inspecting test.log you should get further. - Andy -- View this message in context: http://www.nabble.com/story-runner-on-restful_authentication-question-tp16941586p16945873.html Sent from the rspec-users mailing list archive at Nabble.com.
on 28.04.2008 22:17
On 28 apr 2008, at 17:31, steven shingler wrote: > > When "the user logs in with username and password" do > post "/sessions/create", :user => { :login => @username, :password > => @password } > end Try post_via_redirect... greetz, bartz
on 29.04.2008 12:48
On Mon, Apr 28, 2008 at 4:16 PM, Bart Zonneveld <loop@superinfinite.com> wrote: > Try post_via_redirect... No that will make his "should redirect to '$path" step fail since it will eat the redirect response and follow it. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/
on 29.04.2008 12:50
On 29-apr-2008, at 12:46, Rick DeNatale wrote: >>> >> >> Try post_via_redirect... > > No that will make his "should redirect to '$path" step fail since it > will eat the redirect response and follow it. Ack, brainfart. I mixed up the two in my head. gr, bartz
on 29.04.2008 12:54
Thank you for all the replies. I'm unable to use ruby-debug, cos am running on JRuby, but a liberal sprinkling of logger.debug in the controllers helped me sort out what was going on the test.log. Thanks for that tip. It made me want for a way of writing something to the log from within the rspec step though - is there a quick way of doing that? Cheers, Steven
on 29.04.2008 13:40
On Tue, Apr 29, 2008 at 6:51 AM, steven shingler <shingler@gmail.com> wrote: > Thank you for all the replies. > I'm unable to use ruby-debug, cos am running on JRuby, I haven't yet used JRuby, but there seems to be a JRuby wrapper for rdebug http://wiki.jruby.org/wiki/Using_the_JRuby_Debugger -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/
on 29.04.2008 14:36
ooh - good spot! thanks :)