given 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/given/expectation.rb +10 -8
- data/lib/given/version.rb +1 -1
- data/test/given/expectation_test.rb +6 -3
- metadata +2 -2
data/lib/given/expectation.rb
CHANGED
@@ -17,7 +17,9 @@ module Given
|
|
17
17
|
|
18
18
|
def check(condition, msg, *args)
|
19
19
|
bool = evaluate_condition(&condition)
|
20
|
-
@test_case.given_check(bool,
|
20
|
+
@test_case.given_check(bool,
|
21
|
+
msg,
|
22
|
+
[@value.inspect, twist] + args)
|
21
23
|
true
|
22
24
|
end
|
23
25
|
|
@@ -29,37 +31,37 @@ module Given
|
|
29
31
|
check(
|
30
32
|
lambda { |value| value == other },
|
31
33
|
"<%s> expected to %sbe equal to\n<%s>.\n",
|
32
|
-
other)
|
34
|
+
other.inspect)
|
33
35
|
end
|
34
36
|
|
35
37
|
def >(other)
|
36
38
|
check(lambda { |value| value > other },
|
37
39
|
"<%s> expected to %sbe greater than\n<%s>.\n",
|
38
|
-
other)
|
40
|
+
other.inspect)
|
39
41
|
end
|
40
42
|
|
41
43
|
def <(other)
|
42
44
|
check(lambda { |value| value < other },
|
43
45
|
"<%s> expected to %sbe less than\n<%s>.\n",
|
44
|
-
other)
|
46
|
+
other.inspect)
|
45
47
|
end
|
46
48
|
|
47
49
|
def <=(other)
|
48
50
|
check(lambda { |value| value <= other },
|
49
51
|
"<%s> expected to %sbe less than or equal to\n<%s>.\n",
|
50
|
-
other)
|
52
|
+
other.inspect)
|
51
53
|
end
|
52
54
|
|
53
55
|
def >=(other)
|
54
56
|
check(lambda { |value| value >= other },
|
55
57
|
"<%s> expected to %sbe greater than or equal to\n<%s>.\n",
|
56
|
-
other)
|
58
|
+
other.inspect)
|
57
59
|
end
|
58
60
|
|
59
61
|
def =~(pattern)
|
60
62
|
check(lambda { |value| value =~ pattern },
|
61
63
|
"<%s> expected to %sbe matched by\n<%s>.\n",
|
62
|
-
pattern)
|
64
|
+
pattern.inspect)
|
63
65
|
end
|
64
66
|
|
65
67
|
def nil?
|
@@ -72,7 +74,7 @@ module Given
|
|
72
74
|
if method_name =~ /\?$/
|
73
75
|
check(lambda { |value| value.send(sym, *args, &block) },
|
74
76
|
"<%s> expected to %sbe %s",
|
75
|
-
|
77
|
+
method_name[0..-2])
|
76
78
|
else
|
77
79
|
fail Given::UsageError.new("cannot expect anything about #{sym}")
|
78
80
|
end
|
data/lib/given/version.rb
CHANGED
@@ -46,6 +46,10 @@ class ExpectationContract < Given::TestCase
|
|
46
46
|
FailsWith(Given.assertion_failed_exception)
|
47
47
|
Then { expect(exception.message) =~ /<1> expected to be equal to.*<2>/m }
|
48
48
|
|
49
|
+
When { expect([1,2]) == [1,3] }
|
50
|
+
FailsWith(Given.assertion_failed_exception)
|
51
|
+
Then { expect(exception.message) =~ /<\[1, 2\]> expected to be equal to.*<\[1, 3\]>/m }
|
52
|
+
|
49
53
|
When { expect(1).not == 1 }
|
50
54
|
FailsWith(Given.assertion_failed_exception)
|
51
55
|
Then { expect(exception.message) =~ /<1> expected to not be equal to.*<1>/m }
|
@@ -68,7 +72,7 @@ class ExpectationContract < Given::TestCase
|
|
68
72
|
|
69
73
|
When { expect("abc") =~ /^x/ }
|
70
74
|
FailsWith(Given.assertion_failed_exception)
|
71
|
-
Then { expect(exception.message) =~ /<abc> expected to be matched by.*\^x/m }
|
75
|
+
Then { expect(exception.message) =~ /<"abc"> expected to be matched by.*\^x/m }
|
72
76
|
|
73
77
|
When { expect(1).nil? }
|
74
78
|
FailsWith(Given.assertion_failed_exception)
|
@@ -76,8 +80,7 @@ class ExpectationContract < Given::TestCase
|
|
76
80
|
|
77
81
|
When { expect([1]).empty? }
|
78
82
|
FailsWith(Given.assertion_failed_exception)
|
79
|
-
Then { expect(exception.message) =~
|
80
|
-
|
83
|
+
Then { expect(exception.message) =~ /<\[1\]> expected to be empty\.?$/m }
|
81
84
|
end
|
82
85
|
|
83
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: given
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Weirich
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-27 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|