Sha256: 46729d4be019c63db6a7f480622d453f04088fd245012b8422c6030861e6e864

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 KB

Contents

require 'teststrap'

context "An assertion" do
  context "that is passing" do
    setup { Riot::Assertion.new("foo") { true } }
    asserts("to_s") { topic.to_s == "foo" }

    asserts(":pass is returned when evaluated") do
      topic.run(Riot::Situation.new) == [:pass]
    end
  end # that is passing

  context "that is failing" do
    setup { Riot::Assertion.new("foo") { nil } }
    asserts("to_s") { topic.to_s == "foo" }

    asserts(":fail and message are evaluated") do
      topic.run(Riot::Situation.new) == [:fail, "Expected non-false but got nil instead"]
    end
  end # that is failing

  context "that is erroring" do
    setup do
      @exception = exception = Exception.new("blah")
      Riot::Assertion.new("baz") { raise exception }
    end

    asserts("to_s") { topic.to_s == "baz" }

    asserts(":error and exception are evaluated") do
      topic.run(Riot::Situation.new) == [:error, @exception]
    end
  end # that is erroring

  context "with no block to provide the actual" do
    setup do
      @situation = Riot::Situation.new
      @situation.topic = "hello"
      Riot::Assertion.new("test")
    end
    should("uses block returning topic as default") do
      topic.equals("hello")
      result = topic.run(@situation)
    end.equals([:pass])
  end
  
  context "with block expectation" do
    setup do
      @situation = Riot::Situation.new
      @situation.topic = "hello"
      Riot::Assertion.new("test")
    end

    should("use block returning topic as default") do
      topic.equals { "hello" }
      result = topic.run(@situation)
    end.equals([:pass])

    asserts("block expectation has access to the situation items") do
      topic.equals { @topic }
      topic.run(@situation)
    end.equals([:pass])
  end
end # An assertion block

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
riot-0.10.9 test/assertion_test.rb
riot-0.10.8 test/assertion_test.rb
riot-0.10.7 test/assertion_test.rb
riot-0.10.6 test/assertion_test.rb
riot-0.10.5 test/assertion_test.rb
riot-0.10.4 test/assertion_test.rb
riot-0.10.3 test/assertion_test.rb