RSpec results

# RSpec Code Examples

Mocker
  should be able to call mock()
  should fail when expected message not received

      Mock 'poke me' expected :poke with (any args) once, but received it 0 times

      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/./examples/failing/mocking_example.rb:13:in `should_receive'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:24:in `run'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `instance_eval'

      11  it "should fail when expected message not received" do
      12    mock = mock("poke me")
      13    mock.should_receive(:poke)
      14  end
      15
      16# gem install syntax to get syntax highlighting

  should fail when messages are received out of order

      Mock 'one two three' received :three out of order

      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/./examples/failing/mocking_example.rb:22:in `three'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/./examples/failing/mocking_example.rb:16:in `instance_eval'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:24:in `run'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `instance_eval'

      20    mock.should_receive(:three).ordered
      21    mock.one
      22    mock.three
      23    mock.two
      24  end
      25# gem install syntax to get syntax highlighting

  should get yelled at when sending unexpected messages

      Mock 'don't talk to me' expected :any_message_at_all with (any args) 0 times, but received it once

      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/./examples/failing/mocking_example.rb:28:in `should_not_receive'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:24:in `run'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `instance_eval'

      26  it "should get yelled at when sending unexpected messages" do
      27    mock = mock("don't talk to me")
      28    mock.should_not_receive(:any_message_at_all)
      29    mock.any_message_at_all
      30  end
      31# gem install syntax to get syntax highlighting

  has a bug we need to fix

      Expected pending 'here is the bug' to fail. No Error was raised.

      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/./examples/failing/mocking_example.rb:33:in `pending'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/./examples/failing/mocking_example.rb:33:in `instance_eval'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:24:in `run'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `instance_eval'

      31
      32  it "has a bug we need to fix" do
      33    pending "here is the bug" do
      34      # Actually, no. It's fixed. This will fail because it passes :-)
      35      mock = mock("Bug")
      36# gem install syntax to get syntax highlighting

Running specs with --diff
  should print diff of different strings

      expected: "RSpec is a\nbehaviour driven development\nframework for Ruby\n",
           got: "RSpec is a\nbehavior driven development\nframework for Ruby\n" (using ==)
      Diff:
      @@ -1,4 +1,4 @@
       RSpec is a
      -behavior driven development
      +behaviour driven development
       framework for Ruby

      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/./examples/failing/diffing_spec.rb:13:in `=='
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:24:in `run'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `instance_eval'

      11framework for Ruby
      12EOF
      13    usa.should == uk
      14  end
      15
      16# gem install syntax to get syntax highlighting

  should print diff of different objects' pretty representation

      expected <Animal
      name=bob,
      species=tortoise
      >
      , got <Animal
      name=bob,
      species=giraffe
      >
       (using .eql?)
      Diff:
      @@ -1,5 +1,5 @@
       <Animal
       name=bob,
      -species=giraffe
      +species=tortoise
       >

      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/./examples/failing/diffing_spec.rb:34:in `should'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/./examples/failing/diffing_spec.rb:31:in `instance_eval'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:24:in `run'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `chdir'
      /Users/david/projects/ruby/jruby/testsuites/rspec/target/rspec/spec/spec/runner/formatter/html_formatter_spec.rb:20:in `instance_eval'

      32    expected = Animal.new "bob", "giraffe"
      33    actual   = Animal.new "bob", "tortoise"
      34    expected.should eql(actual)
      35  end
      36end
      37# gem install syntax to get syntax highlighting

A consumer of a stub
  should be able to stub methods on any Object

A stubbed method on a class
  should return the stubbed value
  should revert to the original method after each spec
  can stub! and mock the same message

A mock
  can stub!
  can stub! and mock
  can stub! and mock the same message

pending example (using pending method)
  should be reported as "PENDING: for some reason" (PENDING: for some reason)

pending example (with no block)
  should be reported as "PENDING: Not Yet Implemented" (PENDING: Not Yet Implemented)

pending example (with block for pending)
  should have a failing block, passed to pending, reported as "PENDING: for some reason" (PENDING: for some reason)