test/context_test.rb in riot-0.9.10 vs test/context_test.rb in riot-0.9.11

- old
+ new

@@ -52,27 +52,54 @@ # # Nested Context context "nested context" do setup do - @parent_context = Riot::Context.new("foo", Riot::NilReport.new) - @parent_context.setup { @test_counter = 0; @foo = "bar" } - @parent_context.asserts("truthiness") { @test_counter += 1; true } - @parent_context + 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 = @parent_context.context("baz") + test_context = topic.context("baz") test_context.setup { @test_counter += 10 } test_context end should("inherit parent context") { topic.situation }.assigns(:test_counter, 10) should("chain context names") { topic.to_s }.equals("foo baz") end context "inner context without its own setup" do - setup { @parent_context.context("bum") } + setup { topic.context("bum") } asserts("parent setup is called") { topic.situation }.assigns(:foo, "bar") end end + +# +# Multiple setups in a context + +context "multiple setups" do + setup do + test_context = Riot::Context.new("foo", Riot::NilReport.new) + test_context.setup { @foo = "bar" } + test_context.setup { @baz = "boo" } + test_context + end + + asserts("foo") { topic.situation }.assigns(:foo, "bar") + asserts("bar") { topic.situation }.assigns(:baz, "boo") + + 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