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
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
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. > > PatRight, get it now, thanks. jh