Failing Flash Spec

I am having failing simple spec which I couldn’t figure out why :frowning:

  • ffaker (0.4.0)
  • machinist (1.0.6)
  • rails (3.0.0.beta3)
  • rspec (2.0.0.beta.8)
  • rspec-core (2.0.0.beta.8)
  • rspec-expectations (2.0.0.beta.8)
  • rspec-mocks (2.0.0.beta.8)
  • rspec-rails (2.0.0.beta.8)

Can someone help.

Thx

On May 15, 2010, at 7:18 PM, Kwang how Tan wrote:

  • rspec-rails (2.0.0.beta.8)

Can someone help.

Not if you don’t post the failure messages :slight_smile: Please do so.

Not if you don’t post the failure messages :slight_smile: Please do so.

Sorry, I don’t understand what you mean.
Please explain.

Thx

On Mon, May 17, 2010 at 4:37 AM, Kwang how Tan [email protected]
wrote:

Not if you don’t post the failure messages :slight_smile: Please do so.

Sorry, I don’t understand what you mean.
Please explain.

Please run the spec and post the failure messages you get. Use the -b
flag you get a full backtrace:

spec spec/controllers/sessions_controller_spec.rb -b

Thanks,
David

On Mon, May 17, 2010 at 9:32 PM, Kwang how Tan [email protected]
wrote:

Here are the failure messages, and the backtraces.

Thx

  1. SessionsController #create authenticate fail flash.now[:error] should
    be set to failure
    Failure/Error: flash.now[:error].should == “Invalid username or
    password!”
    expected: “Invalid username or password!”,
    got: nil (using ==)

I think the problem here is that the expectation is set on flash.now,
but that’s not how flash.now works - views still just access flash
(not flash.now). Try this:

  it 'flash.now[:error] should be set to failure' do
    post :create
    flash[:error].should == "Invalid username or password!"
  end
  1. SessionsController #create authenticate successfully should redirect
    Failure/Error:
    expects(:redirect_to_target_or_default).with(twikets_path)

And in this case the expects message is being sent to the example
group, not the controller. Try:

controller.expects(:redirect_to_target_or_default).with(twikets_path)

HTH,
David

Both Spec still fail :frowning:

  1. SessionsController #create authenticate fail flash.now[:error] should
    be set to failure
    Failure/Error: flash[:error].should == “Invalid username or
    password!”
    expected: “Invalid username or password!”,
    got: nil (using ==)

/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/expectations/fail_with.rb:23:in
fail_with' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/matchers/operator_matcher.rb:39:infail_with_message’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/matchers/operator_matcher.rb:61:in
__delegate_operator' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/matchers/operator_matcher.rb:51:ineval_match’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/matchers/operator_matcher.rb:29:in
block in use_custom_matcher_or_delegate' # ./spec/controllers/sessions_spec.rb:33:inblock (4 levels) in
<top (required)>’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:41:in
instance_eval' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:41:inblock in run’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:39:in
catch' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:39:inrun’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:181:in
block in run_examples' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:179:inmap’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:179:in
run_examples' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:171:inrun’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:in
block in run_all' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:ineach’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:in
inject' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:inrun_all’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:27:in
block in run' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:34:inblock in report’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:140:in
sync_output' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:29:inreport’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:26:in
run' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:12:inblock in autorun’

  1. SessionsController #create authenticate successfully should redirect
    Failure/Error:
    controller.expects(:redirect_to_target_or_default).with(twikets_path)
    undefined local variable or method `controller’ for
    #Rspec::Core::ExampleGroup::Nested_1::Nested_2::Nested_2:0xc256ef4

/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/matchers/method_missing.rb:6:in
method_missing' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/actionpack-3.0.0.beta3/lib/action_dispatch/testing/assertions/routing.rb:174:inmethod_missing’
# ./spec/controllers/sessions_spec.rb:44:in block (4 levels) in <top (required)>' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:41:ininstance_eval’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:41:in
block in run' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:39:incatch’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:39:in
run' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:181:inblock in run_examples’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:179:in
map' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:179:inrun_examples’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:171:in
run' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:inblock in run_all’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:in
each' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:ininject’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:in
run_all' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:27:inblock in run’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:34:in
block in report' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:140:insync_output’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:29:in
report' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:26:inrun’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:12:in
`block in autorun’

Finished in 0.40236 seconds
14 examples, 2 failures

Here are the failure messages, and the backtraces.

Thx

  1. SessionsController #create authenticate fail flash.now[:error] should
    be set to failure
    Failure/Error: flash.now[:error].should == “Invalid username or
    password!”
    expected: “Invalid username or password!”,
    got: nil (using ==)

/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/expectations/fail_with.rb:23:in
fail_with' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/matchers/operator_matcher.rb:39:infail_with_message’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/matchers/operator_matcher.rb:61:in
__delegate_operator' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/matchers/operator_matcher.rb:51:ineval_match’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-expectations-2.0.0.beta.8/lib/rspec/matchers/operator_matcher.rb:29:in
block in use_custom_matcher_or_delegate' # ./spec/controllers/sessions_spec.rb:33:inblock (4 levels) in
<top (required)>’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:41:in
instance_eval' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:41:inblock in run’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:39:in
catch' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:39:inrun’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:181:in
block in run_examples' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:179:inmap’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:179:in
run_examples' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:171:inrun’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:in
block in run_all' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:ineach’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:in
inject' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:inrun_all’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:27:in
block in run' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:34:inblock in report’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:140:in
sync_output' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:29:inreport’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:26:in
run' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:12:inblock in autorun’

  1. SessionsController #create authenticate successfully should redirect
    Failure/Error:
    expects(:redirect_to_target_or_default).with(twikets_path)
    not all expectations were satisfied
    unsatisfied expectations:
    • expected exactly once, not yet invoked:
      #Rspec::Core::ExampleGroup::Nested_1::Nested_2::Nested_2:0xe058520.redirect_to_target_or_default(’/twikets’)
      satisfied expectations:
    • allowed any number of times, already invoked once: User(id:
      integer, username: string, name: string, password_hash: string,
      password_salt: string, status: string, lock_version: integer,
      created_at: datetime, updated_at: datetime).authenticate(any_parameters)

    ./spec/controllers/sessions_spec.rb:44:in `block (4 levels) in

<top (required)>’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:41:in
instance_eval' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:41:inblock in run’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:39:in
catch' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example.rb:39:inrun’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:181:in
block in run_examples' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:179:inmap’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:179:in
run_examples' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/example_group.rb:171:inrun’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:in
block in run_all' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:ineach’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:in
inject' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:51:inrun_all’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:27:in
block in run' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:34:inblock in report’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:140:in
sync_output' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/formatters/base_formatter.rb:29:inreport’
#
/home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:26:in
run' # /home/tkhow/.rvm/gems/ruby-1.9.1-p378/gems/rspec-core-2.0.0.beta.8/lib/rspec/core/runner.rb:12:inblock in autorun’

Finished in 0.47966 seconds
14 examples, 2 failures