2018-10-20 02:30:27 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
describe Spectator::Internals::Harness do
|
|
|
|
describe "#run" do
|
|
|
|
it "runs an example" do
|
|
|
|
run_count = 0
|
|
|
|
spy = SpyExample.create do
|
|
|
|
run_count += 1
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
run_count.should eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a passing exmaple" do
|
2018-10-21 14:10:59 +00:00
|
|
|
it "returns a passing result" do
|
|
|
|
example = PassingExample.create
|
|
|
|
result = Spectator::Internals::Harness.run(example)
|
|
|
|
result.passed?.should be_true
|
2018-10-20 02:30:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a failing example" do
|
2018-10-21 14:10:59 +00:00
|
|
|
it "returns a failing result" do
|
|
|
|
example = FailingExample.create
|
|
|
|
result = Spectator::Internals::Harness.run(example)
|
|
|
|
result.passed?.should be_false
|
2018-10-20 02:30:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#current" do
|
|
|
|
it "references the current harness" do
|
|
|
|
harness = nil.as(Spectator::Internals::Harness?)
|
|
|
|
spy = SpyExample.create do
|
|
|
|
harness = Spectator::Internals::Harness.current
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
harness.should be_a(Spectator::Internals::Harness)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#example" do
|
|
|
|
it "references the current example" do
|
|
|
|
example = nil.as(Spectator::Example?)
|
|
|
|
spy = SpyExample.create do
|
|
|
|
example = Spectator::Internals::Harness.current.example
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
example.should be(spy)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#report_expectation" do
|
|
|
|
context "with a successful result" do
|
|
|
|
it "stores the result" do
|
2018-10-22 16:49:42 +00:00
|
|
|
error = nil.as(Exception?)
|
2018-11-14 09:15:55 +00:00
|
|
|
expectation = new_satisfied_expectation
|
2018-10-22 16:49:42 +00:00
|
|
|
spy = SpyExample.create do
|
|
|
|
harness = Spectator::Internals::Harness.current
|
2018-11-14 09:15:55 +00:00
|
|
|
harness.report_expectation(expectation)
|
2018-10-22 16:49:42 +00:00
|
|
|
end
|
|
|
|
result = Spectator::Internals::Harness.run(spy)
|
|
|
|
result.should be_a(Spectator::SuccessfulResult)
|
2018-11-14 09:15:55 +00:00
|
|
|
result.as(Spectator::SuccessfulResult).expectations.should contain(expectation)
|
2018-10-20 02:30:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a failed result" do
|
|
|
|
it "raises an error" do
|
2018-10-21 14:10:59 +00:00
|
|
|
error = nil.as(Exception?)
|
|
|
|
spy = SpyExample.create do
|
|
|
|
harness = Spectator::Internals::Harness.current
|
|
|
|
begin
|
2018-11-14 09:15:55 +00:00
|
|
|
harness.report_expectation(new_unsatisfied_expectation)
|
2018-10-21 14:10:59 +00:00
|
|
|
rescue ex
|
|
|
|
error = ex
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
error.should be_a(Spectator::ExampleFailed)
|
2018-10-20 02:30:27 +00:00
|
|
|
end
|
2018-10-22 16:49:42 +00:00
|
|
|
|
|
|
|
it "stores the result" do
|
|
|
|
error = nil.as(Exception?)
|
2018-11-14 09:15:55 +00:00
|
|
|
expectation = new_unsatisfied_expectation
|
2018-10-22 16:49:42 +00:00
|
|
|
spy = SpyExample.create do
|
|
|
|
harness = Spectator::Internals::Harness.current
|
2018-11-14 09:15:55 +00:00
|
|
|
harness.report_expectation(expectation)
|
2018-10-22 16:49:42 +00:00
|
|
|
end
|
|
|
|
result = Spectator::Internals::Harness.run(spy)
|
|
|
|
result.should be_a(Spectator::FailedResult)
|
2018-11-14 09:15:55 +00:00
|
|
|
result.as(Spectator::FailedResult).expectations.should contain(expectation)
|
2018-10-22 16:49:42 +00:00
|
|
|
end
|
2018-10-20 02:30:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#expectation_results" do
|
|
|
|
it "contains the reported results" do
|
2018-11-14 09:15:55 +00:00
|
|
|
expectations = [new_satisfied_expectation, new_unsatisfied_expectation]
|
2018-10-22 16:49:42 +00:00
|
|
|
spy = SpyExample.create do
|
|
|
|
harness = Spectator::Internals::Harness.current
|
2018-11-14 09:15:55 +00:00
|
|
|
expectations.each do |expectation|
|
|
|
|
harness.report_expectation(expectation)
|
2018-10-22 16:49:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
result = Spectator::Internals::Harness.run(spy)
|
|
|
|
reported_results = result.as(Spectator::FailedResult).expectations.to_a
|
2018-11-14 09:15:55 +00:00
|
|
|
(expectations - reported_results).size.should eq(0)
|
2018-10-20 02:30:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|