Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Train Message homework--rspec #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 16 additions & 5 deletions train.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
class Conductor
attr_reader :messageBoard
Copy link
Member

Choose a reason for hiding this comment

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

In Ruby, the conventions for variables are :message_board rather than messageBoard like JavaScript.


attr_reader :engineer

def initialize(engineer)
@engineer = engineer
def initialize(messageBoard)
@messageBoard = messageBoard
end

def see_danger_coming!
engineer.slow_down!
messageBoard.slow_down!
end
end

class Engineer
attr_reader :messageBoard

def initialize(messageBoard)
@messageBoard = messageBoard
end

def slows_down
messageBoard.confirm_slowdown!
end
end

class MessageBoard
end
22 changes: 16 additions & 6 deletions train_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
require 'rspec'
require '../../../spec_helper'
require './train'
describe Conductor do

let(:engineer) { Engineer.new }
let(:conductor) { Conductor.new(engineer)}
describe Conductor do
let(:messageBoard) {MessageBoard.new}
let(:conductor) {Conductor.new(messageBoard)}

it "should tell the engineer to slow down" do
engineer.should_receive(:slow_down!)
it "should tell the messageboard to slowdown" do
messageBoard.should_receive(:slow_down!)
conductor.see_danger_coming!
end

end

describe Engineer do
let(:messageBoard) {MessageBoard.new}
let(:engineer) {Engineer.new(messageBoard)}

it "should tell the messageBoard slowdown was confirmed" do
messageBoard.should_receive(:confirm_slowdown!)
engineer.slows_down
end
end
4 changes: 2 additions & 2 deletions train_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
require 'minitest/mock'
require './train'

class ConductorTest < MiniTest::Unit::TestCase
class ConductorTest < Minitest::Test
Copy link
Member

Choose a reason for hiding this comment

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

Cool, you're on Minitest 5. awesome!


def setup
@engineer = MiniTest::Mock.new
@engineer = Minitest::Mock.new
@conductor = Conductor.new(@engineer)
end

Expand Down