File: equivalent_to_test.rb

package info (click to toggle)
ruby-riot 0.12.7-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 496 kB
  • ctags: 319
  • sloc: ruby: 2,572; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 2,126 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
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 equivalent_to assertion macro" do
  setup { Riot::Assertion.new("red") { "what" } }

  asserts("String is equivalent to 'what'") do
    topic.equivalent_to(String).run(Riot::Situation.new)
  end.equals([:pass, "is equivalent to String"])

  asserts("an array is not equivalent to 'what'") do
    topic.equivalent_to([]).run(Riot::Situation.new)[0..1]
  end.equals([:fail, 'expected "what" to be equivalent to []'])

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

    asserts(":pass when in expected range") do
      topic.equivalent_to(30000..32000).run(Riot::Situation.new)
    end.equals([:pass, "is equivalent to 30000..32000"])

    asserts ":fail when not in expected range" do 
      topic.equivalent_to(32000..33000).run(Riot::Situation.new)[0..1]
    end.equals([:fail, 'expected 31413 to be equivalent to 32000..33000'])

  end # with numeric topic

end # An equivalent_to assertion macro

context "A negative equivalent_to assertion macro" do
  setup { Riot::Assertion.new("red", true) { "what" } }
  
  asserts("String is not equivalent to 'what'") do
    topic.equivalent_to(String).run(Riot::Situation.new)[0..1]
  end.equals([:fail, 'expected "what" not to be equivalent to String'])

  asserts("an array is not equivalent to 'what'") do
    topic.equivalent_to([]).run(Riot::Situation.new)
  end.equals([:pass, "is equivalent to []"])

  context "with numeric topic" do
    setup { Riot::Assertion.new("blue", true) { 31413 } }

    asserts(":fail when not in expected range") do
      topic.equivalent_to(30000..32000).run(Riot::Situation.new)[0..1]
    end.equals([:fail, "expected 31413 not to be equivalent to 30000..32000"])

    asserts ":pass when in expected range" do 
      topic.equivalent_to(32000..33000).run(Riot::Situation.new)
    end.equals([:pass, "is equivalent to 32000..33000"])
    
  end # with numeric topic
end # A negative equivalent_to assertion macro