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 => “[email protected]” })
@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 Mon, Apr 28, 2008 at 8:31 AM, steven shingler [email protected]
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
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.
–
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 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-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
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 Mon, Apr 28, 2008 at 4:16 PM, Bart Z. [email protected]
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 Tue, Apr 29, 2008 at 6:51 AM, steven shingler [email protected]
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/