Skip to content

Commit

Permalink
Rspec 3.2 syntax for all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vickash committed Mar 3, 2015
1 parent cf895f6 commit 3a8d73c
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 119 deletions.
4 changes: 2 additions & 2 deletions spec/lib/components/basic/analog_input_spec.rb
Expand Up @@ -10,14 +10,14 @@ module Basic

describe '#_read' do
it 'should send #analog_read to the board with its pin' do
board.should_receive(:analog_read).with(subject.pin)
expect(board).to receive(:analog_read).with(subject.pin)
subject._read
end
end

describe '#_listen' do
it 'should send #analog_listen to the board with its pin' do
board.should_receive(:analog_listen).with(subject.pin)
expect(board).to receive(:analog_listen).with(subject.pin)
subject._listen
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/components/basic/analog_output_spec.rb
Expand Up @@ -10,27 +10,27 @@ module Basic

describe '#analog_write' do
it 'should update the @state instance variable and call #analog_write on the board' do
board.should_receive(:analog_write).with(subject.pin, 128).once
expect(board).to receive(:analog_write).with(subject.pin, 128).once

subject.analog_write(128)
subject.state.should == 128
expect(subject.state).to eq(128)
end
end

describe '#write' do
it 'should call #digital_write if value is HIGH' do
subject.should_receive(:digital_write).with(board.high)
expect(subject).to receive(:digital_write).with(board.high)
subject.write(board.high)
end


it 'should call #digital_write if value is LOW' do
subject.should_receive(:digital_write).with(board.low)
expect(subject).to receive(:digital_write).with(board.low)
subject.write(board.low)
end

it 'should call #analog_write if value is anything else' do
subject.should_receive(:analog_write).with(128)
expect(subject).to receive(:analog_write).with(128)
subject.write(128)
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/lib/components/basic/digital_output_spec.rb
Expand Up @@ -10,44 +10,44 @@ module Basic

describe '#after_initialize' do
it 'should set mode to out and go low' do
board.should_receive(:digital_write).with(13, board.low)
expect(board).to receive(:digital_write).with(13, board.low)
subject
end
end

describe '#digital_write' do
it 'should update the @state instance variable and call #digital_write on the board' do
subject
board.should_receive(:digital_write).with(subject.pin, board.high).once
expect(board).to receive(:digital_write).with(subject.pin, board.high).once
subject.digital_write(board.high)
subject.state.should == board.high
expect(subject.state).to eq(board.high)
end
end

describe '#high' do
it 'should call #digital_write with HIGH' do
subject.should_receive(:digital_write).with(board.high)
expect(subject).to receive(:digital_write).with(board.high)
subject.high
end
end

describe '#low' do
it 'should call #digital_write with LOW' do
subject.should_receive(:digital_write).with(board.low)
expect(subject).to receive(:digital_write).with(board.low)
subject.low
end
end

describe '#toggle' do
it 'should call high if currently LOW' do
subject.low
subject.should_receive(:high)
expect(subject).to receive(:high)
subject.toggle
end

it 'should call LOW if anything else' do
subject.high
subject.should_receive(:low)
expect(subject).to receive(:low)
subject.toggle
end
end
Expand Down
38 changes: 19 additions & 19 deletions spec/lib/components/lcd_spec.rb
Expand Up @@ -7,121 +7,121 @@ module Components
subject { LCD.new board: board, pins: { rs: 12, enable: 11, d4: 5, d5: 4, d6: 3, d7: 2 }, cols: 16, rows: 2 }

before do
board.should_receive(:write).with("10..0.12,11,5,4,3,2\n")
board.should_receive(:write).with("10..1.16,2\n")
expect(board).to receive(:write).with("10..0.12,11,5,4,3,2\n")
expect(board).to receive(:write).with("10..1.16,2\n")
end

describe '#clear' do
it 'clears the display' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 2)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 2)
subject.clear
end
end

describe '#home' do
it 'Moves the cursor to the first position' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 3)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 3)
subject.home
end
end

describe '#set_cursor' do
it 'moves the cursor to the given position' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 4, aux_message: "0,1")
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 4, aux_message: "0,1")
subject.set_cursor(0,1)
end
end

describe '#puts' do
it 'prints a string in the display' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 5, aux_message: "AB")
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 5, aux_message: "AB")
subject.puts("AB")
end
end

describe '#show_cursor' do
it 'shows the cursor' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 6)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 6)
subject.show_cursor
end
end

describe '#hide_cursor' do
it 'hides the cursor' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 7)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 7)
subject.hide_cursor
end
end

describe '#blink' do
it 'shows a blinking cursor' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 8)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 8)
subject.blink
end
end

describe '#no_blink' do
it 'stops a blinking cursor' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 9)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 9)
subject.no_blink
end
end

describe '#on' do
it 'turn on the display' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 10)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 10)
subject.on
end
end

describe '#off' do
it 'turn off the display' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 11)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 11)
subject.off
end
end

describe '#scroll_left' do
it 'move the text in the display one position to the left' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 12)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 12)
subject.scroll_left
end
end

describe '#scroll_right' do
it 'move the text in the display one position to the right' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 13)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 13)
subject.scroll_right
end
end

describe '#enable_autoscroll' do
it 'enable autoscroll' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 14)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 14)
subject.enable_autoscroll
end
end

describe '#disable_autoscroll' do
it 'disable autoscroll' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 15)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 15)
subject.disable_autoscroll
end
end

describe '#left_to_right' do
it 'set the display writing to start from the left' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 16)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 16)
subject.left_to_right
end
end

describe '#right_to_left' do
it 'set the display writing to start from the right' do
board.should_receive(:write).with Dino::Message.encode(command: 10, value: 17)
expect(board).to receive(:write).with Dino::Message.encode(command: 10, value: 17)
subject.right_to_left
end
end
end
end
end
end
26 changes: 13 additions & 13 deletions spec/lib/components/rgb_led_spec.rb
Expand Up @@ -10,26 +10,26 @@ module Components
describe '#initialize' do
it 'should create a BaseOutput instance for each pin' do
led = RgbLed.new(options)
led.red.class.should == Basic::AnalogOutput
led.green.class.should == Basic::AnalogOutput
led.blue.class.should == Basic::AnalogOutput

expect(led.red.class).to eq(Basic::AnalogOutput)
expect(led.green.class).to eq(Basic::AnalogOutput)
expect(led.blue.class).to eq(Basic::AnalogOutput)
end
end

describe '#write' do
it 'should write the elements of the array to red, green and blue' do
subject.red.should_receive(:write).with(0)
subject.green.should_receive(:write).with(128)
subject.blue.should_receive(:write).with(0)
expect(subject.red).to receive(:write).with(0)
expect(subject.green).to receive(:write).with(128)
expect(subject.blue).to receive(:write).with(0)

subject.write [0, 128, 0]
end
end

describe '#color=' do
it 'should write an array of values' do
subject.should_receive(:write).with([128, 0, 0])
expect(subject).to receive(:write).with([128, 0, 0])
subject.color = [128, 0, 0]
end

Expand All @@ -44,7 +44,7 @@ module Components
white: [255, 255, 255],
off: [000, 000, 000]
}
colors.each_value { |color| subject.should_receive(:write).with(color).twice }
colors.each_value { |color| expect(subject).to receive(:write).with(color).twice }

colors.each_key { |key| subject.color = key }
colors.each_key { |key| subject.color = key.to_s }
Expand All @@ -53,10 +53,10 @@ module Components

describe '#cycle' do
it 'should cycle through the 3 base colors' do
Array.any_instance.should_receive(:cycle).and_yield(:red).and_yield(:green).and_yield(:blue)
subject.should_receive(:color=).with(:red)
subject.should_receive(:color=).with(:green)
subject.should_receive(:color=).with(:blue)
expect_any_instance_of(Array).to receive(:cycle).and_yield(:red).and_yield(:green).and_yield(:blue)
expect(subject).to receive(:color=).with(:red)
expect(subject).to receive(:color=).with(:green)
expect(subject).to receive(:color=).with(:blue)
subject.cycle
end
end
Expand Down
11 changes: 5 additions & 6 deletions spec/lib/components/servo_spec.rb
Expand Up @@ -9,7 +9,7 @@ module Components

describe '#initialize' do
it 'should toggle the servo library on for the pin' do
board.should_receive(:servo_toggle).with(options[:pin], 1)
expect(board).to receive(:servo_toggle).with(options[:pin], 1)
subject
end
end
Expand All @@ -19,25 +19,24 @@ module Components

it 'should set the position of the Servo' do
servo.position = 90
servo.position.should == 90
expect(servo.position).to eq(90)
end

it 'should let you write up to 180' do
servo.position = 180
servo.position.should == 180
expect(servo.position).to eq(180)
end

it 'should modulate when position > 180' do
servo.position = 190
servo.position.should == 10
expect(servo.position).to eq(10)
end

it 'should write the new position to the board' do
board.should_receive(:servo_write).with(13, 10)
expect(board).to receive(:servo_write).with(13, 10)
servo.position = 190
end
end
end
end
end

4 changes: 2 additions & 2 deletions spec/lib/components/setup/base_spec.rb
Expand Up @@ -11,7 +11,7 @@ class BaseComponent
include Base
end
subject { BaseComponent.new(options) }

describe '#initialize' do
it 'should require a board' do
expect {
Expand All @@ -20,7 +20,7 @@ class BaseComponent
end

it 'should register itself as a component on the board' do
board.should_receive(:add_component)
expect(board).to receive(:add_component)
BaseComponent.new(options)
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/components/setup/input_spec.rb
Expand Up @@ -16,15 +16,15 @@ class InputComponent
describe '#pullup=' do
it 'should tell the board to set the pullup mode correctly' do
subject
board.should_receive(:set_pullup).with(subject.pin, false)
expect(board).to receive(:set_pullup).with(subject.pin, false)
subject.pullup = false
subject.pullup.should == false
expect(subject.pullup).to be(false)
end
end

describe '#initialize_pins' do
it 'should set the pin mode to in' do
board.should_receive(:set_pin_mode).with(board.convert_pin(options[:pin]), :in)
expect(board).to receive(:set_pin_mode).with(board.convert_pin(options[:pin]), :in)
subject
end

Expand All @@ -34,7 +34,7 @@ class InputComponent
end

it 'should tell the board to start reading' do
board.should_receive(:start_read)
expect(board).to receive(:start_read)
subject
end
end
Expand Down

0 comments on commit 3a8d73c

Please sign in to comment.