[rspec-users] Strange error in StoryRunner (was: Mocks in StoryRunner)

James Hughes hughes.james at gmail.com
Wed Sep 19 14:14:28 EDT 2007


Hi,
I'm posting this stack trace again because it keeps popping up,
seemingly as the 'default error' when something is wrong with my story
code; for instance, I got it when I referenced a variable in my
'Given' that I had forgotten to pass into the block.

Now I'm getting it when I attempt to post to a login action:

    And 'user is logged in as', 'jhughes' do |login|
      post '/login', :login => login, :password => 'secret'
    end
#post calls reset!, leading to the errors on the top of the stack below.

This is still happening after updating to the latest rspec trunk about
5 minutes ago. Rails version is 1.2.3.

I'm sure this is something wrong with my code/setup, but I thought I'd
bring it up again as it seems that StoryRunner should probably die
with a more informative error when something's wrong.

thanks,
James



On 9/14/07, Pat Maddox <pergesu at gmail.com> wrote:
> On 9/14/07, James Hughes <hughes.james at gmail.com> wrote:
> > Hi,
> >
> > I'm trying to get up and running with StoryRunner. I have a story that
> > looks something like the following, but the call to mock_model
> > produces the exception listed below. Am I just misunderstanding the
> > concept? Are mocks not meant to be used in stories like this? Or is
> > this a bug? Changing @user to be an actual AR object makes things run
> > without error.
> >
> > ENV["RAILS_ENV"] = "test"
> > require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
> > require 'spec'
> > require 'spec/rails'
> > require 'spec/rails/story_adapter'
> >
> > Story 'Something happens', %{
> >   As a user
> >   I want to do something
> >   So that something will happen.
> > }, :type => RailsStory do
> >
> >   Scenario 'User doing something for first time' do
> >     Given 'a user' do
> >       @user = mock_model(User)
> >     end
> >     When 'the user makes a request' do
> >     end
> >     Then 'something should happen' do
> >     end
> >   end
> > end
> >
> >
> > Here's the stack trace:
> >
> > 1 scenarios: 0 succeeded, 1 failed, 0 pending
> >
> > FAILURES:
> >   1) Something happens (User doing something for first time) FAILED
> >   NoMethodError: You have a nil object when you didn't expect it!
> > You might have expected an instance of Array.
> > The error occurred while evaluating nil.each
> >   /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:519:in
> > `open_session'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:490:in
> > `reset!'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/integration.rb:546:in
> > `method_missing'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/matchers.rb:146:in
> > `method_missing'
> > stories/use_case_story.rb:38:in `a logged-in user'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/simple_step.rb:13:in
> > `__send__'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/simple_step.rb:13:in
> > `perform'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/world.rb:58:in
> > `store_and_call'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/world.rb:68:in
> > `Given'
> > stories/use_case_story.rb:36
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/runner/scenario_runner.rb:13:in
> > `instance_eval'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/runner/scenario_runner.rb:13:in
> > `run'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/runner/story_runner.rb:48:in
> > `run_stories'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/runner/story_runner.rb:43:in
> > `each'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/runner/story_runner.rb:43:in
> > `run_stories'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/runner/story_runner.rb:39:in
> > `each'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/runner/story_runner.rb:39:in
> > `run_stories'
> > /home/jhughes/dev/rj/csite/config/../vendor/plugins/rspec/lib/spec/story/runner.rb:36:in
> > `register_exit_hook'
> > stories/use_case_story.rb:29
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>
> No, you shouldn't be calling mock_model in Story Runner.  The whole
> point of stories is to exercise the full functionality of your app.
>
> Pat
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list