Add specs for result types

This commit is contained in:
Michael Miller 2018-11-16 11:39:07 -07:00
parent ee2491fef8
commit 05c3a75683
4 changed files with 254 additions and 0 deletions

View file

@ -0,0 +1,73 @@
require "./spec_helper"
def new_errored_result(
example : Spectator::Example? = nil,
elapsed : Time::Span? = nil,
expectations : Spectator::Expectations::ExampleExpectations? = nil,
error : Exception? = nil
)
Spectator::ErroredResult.new(
example || FailingExample.create,
elapsed || Time::Span.zero,
expectations || Spectator::Expectations::ExampleExpectations.new(generate_expectations(0, 1)[:expectations]),
error || Exception.new("foobar")
)
end
describe Spectator::ErroredResult do
describe "#errored?" do
it "is true" do
new_errored_result.errored?.should be_true
end
end
describe "#passed?" do
it "is false" do
new_errored_result.passed?.should be_false
end
end
describe "#failed?" do
it "is true" do
new_errored_result.failed?.should be_true
end
end
describe "#pending?" do
it "is false" do
new_errored_result.pending?.should be_false
end
end
describe "#example" do
it "is the expected value" do
example = FailingExample.create
result = new_errored_result(example: example)
result.example.should eq(example)
end
end
describe "#elapsed" do
it "is the expected value" do
elapsed = Time::Span.new(10, 10, 10)
result = new_errored_result(elapsed: elapsed)
result.elapsed.should eq(elapsed)
end
end
describe "#expectations" do
it "is the expected value" do
expectations = Spectator::Expectations::ExampleExpectations.new(generate_expectations(5, 1)[:expectations])
result = new_errored_result(expectations: expectations)
result.expectations.should eq(expectations)
end
end
describe "#error" do
it "is the expected value" do
error = IO::Error.new("oops")
result = new_errored_result(error: error)
result.error.should eq(error)
end
end
end

View file

@ -0,0 +1,73 @@
require "./spec_helper"
def new_failed_result(
example : Spectator::Example? = nil,
elapsed : Time::Span? = nil,
expectations : Spectator::Expectations::ExampleExpectations? = nil,
error : Exception? = nil
)
Spectator::FailedResult.new(
example || FailingExample.create,
elapsed || Time::Span.zero,
expectations || Spectator::Expectations::ExampleExpectations.new(generate_expectations(0, 1)[:expectations]),
error || Exception.new("foobar")
)
end
describe Spectator::FailedResult do
describe "#passed?" do
it "is false" do
new_failed_result.passed?.should be_false
end
end
describe "#failed?" do
it "is true" do
new_failed_result.failed?.should be_true
end
end
describe "#errored?" do
it "is false" do
new_failed_result.errored?.should be_false
end
end
describe "#pending?" do
it "is false" do
new_failed_result.pending?.should be_false
end
end
describe "#example" do
it "is the expected value" do
example = FailingExample.create
result = new_failed_result(example: example)
result.example.should eq(example)
end
end
describe "#elapsed" do
it "is the expected value" do
elapsed = Time::Span.new(10, 10, 10)
result = new_failed_result(elapsed: elapsed)
result.elapsed.should eq(elapsed)
end
end
describe "#expectations" do
it "is the expected value" do
expectations = Spectator::Expectations::ExampleExpectations.new(generate_expectations(5, 1)[:expectations])
result = new_failed_result(expectations: expectations)
result.expectations.should eq(expectations)
end
end
describe "#error" do
it "is the expected value" do
error = IO::Error.new("oops")
result = new_failed_result(error: error)
result.error.should eq(error)
end
end
end

View file

@ -0,0 +1,45 @@
require "./spec_helper"
def new_pending_result(example : Spectator::Example? = nil)
Spectator::PendingResult.new(example || FailingExample.create)
end
describe Spectator::PendingResult do
describe "#pending?" do
it "is true" do
new_pending_result.pending?.should be_true
end
end
describe "#passed?" do
it "is false" do
new_pending_result.passed?.should be_false
end
end
describe "#failed?" do
it "is false" do
new_pending_result.failed?.should be_false
end
end
describe "#errored?" do
it "is false" do
new_pending_result.errored?.should be_false
end
end
describe "#example" do
it "is the expected value" do
example = PassingExample.create
result = new_pending_result(example: example)
result.example.should eq(example)
end
end
describe "#elapsed" do
it "is zero" do
new_pending_result.elapsed.should eq(Time::Span.zero)
end
end
end

View file

@ -0,0 +1,63 @@
require "./spec_helper"
def new_successful_result(
example : Spectator::Example? = nil,
elapsed : Time::Span? = nil,
expectations : Spectator::Expectations::ExampleExpectations? = nil
)
Spectator::SuccessfulResult.new(
example || PassingExample.create,
elapsed || Time::Span.zero,
expectations || Spectator::Expectations::ExampleExpectations.new(generate_expectations(1, 0)[:expectations])
)
end
describe Spectator::SuccessfulResult do
describe "#passed?" do
it "is true" do
new_successful_result.passed?.should be_true
end
end
describe "#failed?" do
it "is false" do
new_successful_result.failed?.should be_false
end
end
describe "#errored?" do
it "is false" do
new_successful_result.errored?.should be_false
end
end
describe "#pending?" do
it "is false" do
new_successful_result.pending?.should be_false
end
end
describe "#example" do
it "is the expected value" do
example = PassingExample.create
result = new_successful_result(example: example)
result.example.should eq(example)
end
end
describe "#elapsed" do
it "is the expected value" do
elapsed = Time::Span.new(10, 10, 10)
result = new_successful_result(elapsed: elapsed)
result.elapsed.should eq(elapsed)
end
end
describe "#expectations" do
it "is the expected value" do
expectations = Spectator::Expectations::ExampleExpectations.new(generate_expectations(5, 0)[:expectations])
result = new_successful_result(expectations: expectations)
result.expectations.should eq(expectations)
end
end
end