test/context_test.rb in riot-0.9.12 vs test/context_test.rb in riot-0.10.0

- old
+ new

@@ -1,105 +1,90 @@ require 'teststrap' -context "any context" do +context "Reporting a context" do setup do - @reporter = Riot::NilReport.new - @context = Riot::Context.new("a", @reporter) + a_context = Riot::Context.new("foobar") do + asserts("passing") { true } + asserts("failing") { false } + asserts("erroring") { raise Exception } + end + a_context.run(MockReporter.new) end - context "that doesn't have passing tests" do - setup do - @context.should("a") { true } - @context.should("b") { false } - @context.should("c") { raise Exception, "blah" } - @context.report + asserts("one passed test") { topic.passes == 1 } + asserts("one failed test") { topic.failures == 1 } + asserts("one errored test") { topic.errors == 1 } +end # Reporting a context + +context "Defining a context with multiple setups" do + setup do + a_context = Riot::Context.new("foobar") do + setup { "foo" } + setup { topic + "bar" } + asserts("blah") { topic == "foobar" } end + a_context.run(MockReporter.new) + end - asserts("passed test count") { @reporter.passes }.equals(1) - asserts("failure count") { @reporter.failures }.equals(1) - asserts("unexpected errors count") { @reporter.errors }.equals(1) - end # that doesn't have passing tests + asserts("all tests pass") { topic.passes == 1 } +end # Defining a context with multiple setups - context "when running setup:" do - setup { @context.setup { "foo" } } - - asserts "topic becomes available to test as result of setup" do - @context.should("bar") { topic }.actual - end.equals("foo") - - asserts "calling topic in context will return assertion that returns topic as the actual" do - @context.topic.actual - end.equals("foo") - end # when running setup -end # any context - -# -# Basic Context - -context "basic context" do +context "Nesting a context" do setup do - test_context = Riot::Context.new("foo", Riot::NilReport.new) - test_context.setup { @test_counter = 0 } - test_context.asserts("truthiness") { @test_counter += 1; true } - test_context.asserts("more truthiness") { @test_counter += 1; true } - test_context + a_context = Riot::Context.new("foobar") do + asserts("passing") { true } + context "bazboo" do + asserts("passing") { true } + asserts("failing") { false } + asserts("erroring") { raise Exception } + end + end + a_context.run(MockReporter.new) end - asserts("context description") { topic.to_s }.equals("foo") - asserts("assertion count") { topic.assertions.length }.equals(2) - should("call setup once per context") { topic.situation }.assigns(:test_counter, 2) -end # basic context + asserts("one passed test") { topic.passes == 2 } + asserts("one failed test") { topic.failures == 1 } + asserts("one errored test") { topic.errors == 1 } -# -# Nested Context + context "with setups" do + setup do + a_context = Riot::Context.new("foobar") do + setup { "foo" } + context "bazboo" do + setup { topic + "bar" } + asserts("passing") { topic == "foobar" } + end + end + a_context.run(MockReporter.new) + end -context "nested context" do + asserts("parent setups are called") { topic.passes == 1 } + end # with setups +end # Nestings a context + +context "Using should" do setup do - test_context = Riot::Context.new("foo", Riot::NilReport.new) - test_context.setup { @test_counter = 0; @foo = "bar" } - test_context.asserts("truthiness") { @test_counter += 1; true } - test_context - end - - context "inner context with own setup" do - setup do - test_context = topic.context("baz") - test_context.setup { @test_counter += 10 } - test_context + a_context = Riot::Context.new("foobar") do + should("pass") { true } + should("fail") { false } + should("error") { raise Exception } end - - should("inherit parent context") { topic.situation }.assigns(:test_counter, 10) - should("chain context names") { topic.to_s }.equals("foo baz") + a_context.run(MockReporter.new) end - context "inner context without its own setup" do - setup { topic.context("bum") } - asserts("parent setup is called") { topic.situation }.assigns(:foo, "bar") - end -end + asserts("one passed test") { topic.passes == 1 } + asserts("one failed test") { topic.failures == 1 } + asserts("one errored test") { topic.errors == 1 } +end # Using should -# -# Multiple setups in a context - -context "multiple setups" do +context "The asserts_topic shortcut" do setup do - test_context = Riot::Context.new("foo", Riot::NilReport.new) - test_context.setup { @foo = "bar" } - test_context.setup { @baz = "boo" } - test_context + Riot::Context.new("foo") {}.asserts_topic end - asserts("foo") { topic.situation }.assigns(:foo, "bar") - asserts("bar") { topic.situation }.assigns(:baz, "boo") + should("return an Assertion") { topic }.kind_of(Riot::Assertion) - context "in the parent of a nested context" do - setup do - test_context = topic.context("goo") - test_context.setup { @goo = "car" } - test_context - end - - asserts("foo") { topic.situation }.assigns(:foo, "bar") - asserts("bar") { topic.situation }.assigns(:baz, "boo") - asserts("goo") { topic.situation }.assigns(:goo, "car") - end # in the parent of a nested context -end # multiple setups + should("return the actual topic as the result of evaling the assertion") do + (situation = Riot::Situation.new).topic = "bar" + topic.equals("bar").run(situation) + end.equals([:pass]) +end # The asserts_topic shortcut