Created
January 4, 2012 10:37
-
-
Save moro/1559501 to your computer and use it in GitHub Desktop.
RSpec example for stug_ruby observer pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
$: << File.dirname(__FILE__) + '/terminal' | |
$: << File.dirname(__FILE__) + '/logic_device' | |
require 'terminal' | |
require 'xor' | |
require 'and' | |
describe LogicDevice do | |
RSpec::Matchers.define :compute do |*data, expect| | |
match do |actual| | |
logic = actual.new(data.size) | |
data.each_with_index do |val, index| | |
logic.get_input_terminal(index).state = val | |
end | |
(@result = logic.get_output_terminal.state) == expect[:to] | |
end | |
failure_message_for_should do | |
RSpec::Expectations::Differ.new.diff_as_object(@result, expect[:to]) | |
end | |
end | |
describe Xor do | |
subject { Xor } | |
it { should compute 1, 0, to: 1 } | |
it { should compute 0, 1, to: 1 } | |
it { should compute 0, 0, to: 0 } | |
it { should compute 1, 1, to: 0 } | |
end | |
describe And do | |
subject { And } | |
it { should compute 1, 1, 1, to: 1 } | |
it { should compute 1, 1, 0, to: 0 } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment