Permalink
Browse files

fixed branching expectations in console integration matchers

improved failure responses
  • Loading branch information...
1 parent 19f2f4a commit 2e7b9cda604b60a1a061b8dc5f4e7741c9e632bc Eugenia Dellapenna & Ian Baker committed Mar 6, 2013
View
21 spec/console_app_specker/console_app_specker_matchers_spec.rb
@@ -77,6 +77,27 @@
subject.negative_failure_message.should == "expected 'expected_output' to not be printed, but it was. full output:\nactual_output"
end
end
+
+ context "when expecting branching output" do
+ let(:expected_output) { {
+ "expected_output" => proc {},
+ "other_expected_output" => proc {}
+ } }
+
+ it "has a correct failure message" do
+ run("echo -n actual_output") do |runner|
+ subject.matches?(runner)
+ subject.failure_message.should == "expected one of 'expected_output', 'other_expected_output' to be printed, but it wasn't. full output:\nactual_output"
+ end
+ end
+
+ it "has a correct negative failure message" do
+ run("echo -n expected_output") do |runner|
+ subject.matches?(runner)
+ subject.negative_failure_message.should == "expected 'expected_output' to not be printed, but it was. full output:\nexpected_output"
+ end
+ end
+ end
end
end
View
16 spec/console_app_specker/specker_runner_spec.rb
@@ -85,16 +85,26 @@ def asset(file)
context "expecting multiple branches" do
context "and one of them matches" do
- it "can be passed a hash of values with callbacks" do
+ it "can be passed a hash of values with callbacks, and returns the matched key" do
run("echo 1 3") do |runner|
branches = {
"1" => proc { 1 },
"2" => proc { 2 },
"3" => proc { 3 }
}
- expect(runner.expect(branches)).to eq 1
- expect(runner.expect(branches)).to eq 3
+ expect(runner.expect(branches)).to eq "1"
+ expect(runner.expect(branches)).to eq "3"
+ end
+ end
+
+ it "calls the matched callback" do
+ callback = mock!
+ run("echo 1 3") do |runner|
+ branches = {
+ "1" => proc { callback }
+ }
+ runner.expect(branches)
end
end
end
View
19 spec/support/console_app_specker_matchers.rb
@@ -11,17 +11,28 @@ def initialize(expected_output, timeout = 30)
def matches?(runner)
raise InvalidInputError unless runner.respond_to?(:expect)
- expected = runner.expect(@expected_output, @timeout)
+ @matched = runner.expect(@expected_output, @timeout)
@full_output = runner.output
- !!expected
+ !!@matched
end
def failure_message
- "expected '#{@expected_output}' to be printed, but it wasn't. full output:\n#@full_output"
+ if @expected_output.is_a?(Hash)
+ expected_keys = @expected_output.keys.map{|key| "'#{key}'"}.join(', ')
+ "expected one of #{expected_keys} to be printed, but it wasn't. full output:\n#@full_output"
+ else
+ "expected '#{@expected_output}' to be printed, but it wasn't. full output:\n#@full_output"
+ end
end
def negative_failure_message
- "expected '#{@expected_output}' to not be printed, but it was. full output:\n#@full_output"
+ if @expected_output.is_a?(Hash)
+ match = @matched
+ else
+ match = @expected_output
+ end
+
+ "expected '#{match}' to not be printed, but it was. full output:\n#@full_output"
end
end
View
3 spec/support/specker_runner.rb
@@ -69,11 +69,12 @@ def expect_branches(branches, timeout)
data = expected.first.match(/(#{branch_names})$/)
matched = data[1]
branches[matched].call
+ matched
end
def numeric_exit_code(status)
status.exitstatus
rescue NoMethodError
status
end
-end
+end

0 comments on commit 2e7b9cd

Please sign in to comment.