File: equals_test.rb

package info (click to toggle)
ruby-riot 0.12.7-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 512 kB
  • sloc: ruby: 2,557; makefile: 2
file content (71 lines) | stat: -rw-r--r-- 2,514 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'teststrap'

# Using == to verify the test because this is the test for :equals itself. Look at assertion_test_passes
# and assertion_test_fails for testing other macros.

context "An equals assertion macro" do
  setup do
    Riot::Assertion.new("blue") { "foo" }
  end

  asserts(":pass when expectation met") do
    topic.equals("foo").run(Riot::Situation.new) == [:pass, %Q{is equal to "foo"}]
  end

  context "that is failing" do
    setup { topic.equals("bar").run(Riot::Situation.new) }

    asserts(":fail") { topic.first == :fail }
    asserts("message") { topic[1] == %Q{expected "bar", not "foo"} }
  end # that is failing

  context "with numeric topic" do
    setup do
      Riot::Assertion.new("blue") { 31415 }
    end

    asserts("failure") do
      topic.equals(30000..32000).run(Riot::Situation.new)[0..1] == [:fail, "expected 30000..32000, not 31415"]
    end
  end # with numeric topic

  context "with block as the expectation" do
    asserts(":pass when block expectation met") do
      topic.equals { "foo" }.run(Riot::Situation.new)
    end.equals([:pass, %Q{is equal to "foo"}])

    asserts(":fail with message when block expectation not met") do
      topic.equals { "bar" }.run(Riot::Situation.new)[0..1]
    end.equals([:fail, %Q{expected "bar", not "foo"}])
  end # with block as the expectation

end # An equals assertion macro

context "A negative equals assertion macro" do
  setup do
    Riot::Assertion.new("that flirgy", true) { "foo" }
  end

  asserts(":pass when values do not match") do
    topic.equals("bar").run(Riot::Situation.new) == [:pass, %Q{is equal to "bar" when it is "foo"}]
  end

  asserts(":fail when values do match") do
    topic.equals("foo").run(Riot::Situation.new)[0..1] == [:fail, %Q{did not expect "foo"}]
  end
  
  asserts("result of evaluating when number outside of range") do
    Riot::Assertion.new("blue", true) { 31415 }.equals(30000..32000).run(Riot::Situation.new)
  end.equals([:pass, "is equal to 30000..32000 when it is 31415"])
  
  context "with block as the expectation" do
    asserts(":pass when block expectation values do not equal") do
      topic.equals { "bazzle" }.run(Riot::Situation.new)
    end.equals([:pass, %Q{is equal to "bazzle" when it is "foo"}])
  
    asserts(":fail with message when block expectation values do equal") do
      topic.equals { "foo" }.run(Riot::Situation.new)[0..1]
    end.equals([:fail, %Q{did not expect "foo"}])
  end # with block as the expectation

end # A negative assertion macro