Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lor
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.FF

Failures:

1) MessageBoard should receive slow down from conductor
Failure/Error: conductor.see_danger_coming!
NameError:
undefined local variable or method `conductor' for #<RSpec::Core::ExampleGroup::Nested_2:0x00000101262710>
# ./train_spec.rb:22:in `block (2 levels) in <top (required)>'

2) MessageBoard should receive a slow down confirmation from the engineer
Failure/Error: message_board.should_receive(:confirm_slow_down!)
(#<MessageBoard:0x0000010086a690>).confirm_slow_down!(any args)
expected: 1 time with any arguments
received: 0 times with any arguments
# ./train_spec.rb:26:in `block (2 levels) in <top (required)>'

Finished in 0.01176 seconds
3 examples, 2 failures

Failed examples:

rspec ./train_spec.rb:20 # MessageBoard should receive slow down from conductor
rspec ./train_spec.rb:25 # MessageBoard should receive a slow down confirmation from the engineer
12 changes: 12 additions & 0 deletions train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ def see_danger_coming!
end

class Engineer

def slow_down!
"Hey, we are slowing down!"
end
end

class MessageBoard


def confirm_slow_down!(conductor)
end

end
33 changes: 32 additions & 1 deletion train_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rspec'
require './train'

describe Conductor do

let(:engineer) { Engineer.new }
Expand All @@ -10,4 +11,34 @@
conductor.see_danger_coming!
end

end
end

describe MessageBoard do

let(:message_board) { MessageBoard.new }
let(:conductor) { Conductor.new(engineer)}
let(:engineer) { Engineer.new }

it "should receive slow down from conductor" do
message_board.should_receive(:slow_down!)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are not performing any actions or calling any methods.

All you are doing with this message expectation is saying that for this test to pass, the message_board should receive a call of slow_down!

The normal flow here would be to then execute some code to see if it happened.

it "should receive slow down from conductor" do
  message_board.should_receive(:slow_down!)
  conductor.see_danger_coming!
end

conductor.see_danger_coming!
end

it "should receive a slow down confirmation from the engineer" do
message_board.should_receive(:confirm_slow_down!)
engineer.should(:slow_down!)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid specification?

It COULD be, if you write it. That is, if you created a customer matcher... But you didn't, so you got an error about a "matcher"

end
end

# Your Assignment
# ---------------

# In most circumstances like this, there's a sort of MessageBoard. Let's create
# the idea of a MessageBoard class that both the engineer and the conductor know
# about.

# 1. When the conductor sees trouble, the conductor tells the `message_board` to slow down
# 2. When the engineer slows down, the engineer tells the `message_board` `confirm_slow_down`

# Use whichever mocking tool you liked the best or are interested in. If you
# don't know what to choose, go with RSpec.