File: test_operator_expectations.rb

package info (click to toggle)
ruby-jnunemaker-matchy 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: ruby: 2,939; makefile: 2
file content (157 lines) | stat: -rw-r--r-- 3,151 bytes parent folder | download | duplicates (3)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
require File.dirname(__FILE__) + '/test_helper.rb'

class TestOperatorExpectations < Test::Unit::TestCase
  # EQUALS (==)
  def test_equals
    3.should == 3
  end
  
  def test_equals_fails
    lambda {
      3.should == 5
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_negative_equals
    3.should_not == 4
  end
  
  def test_negative_equals_fails
    lambda {
      3.should_not == 3
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  # LESS THAN (<)
  def test_less_than
    3.should < 5
  end
  
  def test_less_than_fails
    lambda {
      4.should < 3
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_less_than_equals
    3.should_not < 2
  end
  
  def test_negative_less_than_fails
    lambda {
      4.should_not < 5
    }.should raise_error(Test::Unit::AssertionFailedError)
  end 
  
  # GREATER THAN (>)
  def test_greater_than
    3.should > 2
  end
  
  def test_greater_than_fails
    lambda {
      4.should > 5
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_greater_than_equals
    3.should_not > 5
  end
  
  def test_negative_greater_than_fails
    lambda {
      4.should_not > 3
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  # LESS THAN EQUAL (<=)
  def test_less_than_equal
    3.should <= 5
  end
  
  def test_less_than_equal_equal
    3.should <= 3
  end
  
  def test_less_than_equal_fails
    lambda {
      4.should <= 3
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_negative_less_than_equal
    3.should_not <= 2
  end
  
  def test_negative_less_than_equal_fails
    lambda {
      4.should_not <= 5
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  # GREATER THAN EQUALS (>=)
  def test_greater_than_equal
    3.should >= 2
  end
  
  def test_greater_than_equal_equals
    3.should >= 3
  end
  
  def test_greater_than_equal_fails
    lambda {
      4.should >= 5
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_negative_greater_than_equal_equals
    3.should_not >= 5
  end
  
  def test_negative_greater_than_equal_fails
    lambda {
      4.should_not >= 3
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  # MATCHES (=~)
  def test_matches
    "hey world".should =~ /world/
  end
  
  def test_matches_fails
    lambda {
      "d00d ur 1337".should =~ /world/
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_negative_matches
    "1337@age".should_not =~ /434/
  end
  
  def test_negative_matches_fails
    lambda {
      "it's a freak out!".should_not =~ /freak/
    }.should raise_error(Test::Unit::AssertionFailedError)
  end
  
  def test_fail_message
    obj = Matchy::Expectations::OperatorExpectation.new(3, true)
    
    def obj.flunk(msg)
      msg
    end
    
    (obj == 4).should == "Expected 3 to == 4."
  end
  
  def test_negative_fail_message
    obj = Matchy::Expectations::OperatorExpectation.new(3, false)
    
    def obj.flunk(msg)
      msg
    end
    
    (obj == 3).should == "Expected 3 to not == 3."
  end
end