bacon-expect 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/README.md +1 -1
- data/bacon-expect.gemspec +1 -1
- data/lib/bacon-expect/expectation.rb +4 -4
- data/lib/bacon-expect/fail_message_renderer.rb +100 -0
- data/lib/bacon-expect/matchers/be.rb +4 -8
- data/lib/bacon-expect/matchers/be_false.rb +3 -2
- data/lib/bacon-expect/matchers/be_generic.rb +3 -15
- data/lib/bacon-expect/matchers/be_nil.rb +2 -2
- data/lib/bacon-expect/matchers/be_true.rb +2 -2
- data/lib/bacon-expect/matchers/be_within.rb +2 -2
- data/lib/bacon-expect/matchers/change.rb +4 -5
- data/lib/bacon-expect/matchers/end_with.rb +2 -2
- data/lib/bacon-expect/matchers/eq.rb +4 -8
- data/lib/bacon-expect/matchers/eql.rb +2 -10
- data/lib/bacon-expect/matchers/have_generic.rb +2 -5
- data/lib/bacon-expect/matchers/have_items.rb +7 -7
- data/lib/bacon-expect/matchers/include.rb +2 -2
- data/lib/bacon-expect/matchers/match.rb +5 -9
- data/lib/bacon-expect/matchers/match_array.rb +6 -6
- data/lib/bacon-expect/matchers/raise_error.rb +4 -4
- data/lib/bacon-expect/matchers/respond_to.rb +2 -2
- data/lib/bacon-expect/matchers/satisfy.rb +2 -2
- data/lib/bacon-expect/matchers/single_method.rb +20 -0
- data/lib/bacon-expect/matchers/start_with.rb +2 -2
- data/run-tests.sh +3 -0
- data/spec_app/spec/helpers/bacon_context.rb +2 -2
- data/spec_app/spec/matchers/be_false_spec.rb +4 -3
- data/spec_app/spec/matchers/be_generic_spec.rb +4 -3
- data/spec_app/spec/matchers/be_nil_spec.rb +8 -3
- data/spec_app/spec/matchers/be_true_spec.rb +4 -3
- data/spec_app/spec/matchers/be_within_spec.rb +4 -4
- data/spec_app/spec/matchers/change_spec.rb +7 -2
- data/spec_app/spec/matchers/end_with_spec.rb +5 -1
- data/spec_app/spec/matchers/equality_spec.rb +11 -4
- data/spec_app/spec/matchers/have_generic_spec.rb +9 -2
- data/spec_app/spec/matchers/have_items_spec.rb +9 -1
- data/spec_app/spec/matchers/include_spec.rb +8 -3
- data/spec_app/spec/matchers/match_array_spec.rb +8 -3
- data/spec_app/spec/matchers/match_spec.rb +6 -2
- data/spec_app/spec/matchers/raise_error_spec.rb +12 -8
- data/spec_app/spec/matchers/respond_to_spec.rb +10 -3
- data/spec_app/spec/matchers/satisfy_spec.rb +5 -1
- data/spec_app/spec/matchers/start_with_spec.rb +5 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2711107918bcdc5c0561e919905602d4aebd88ef
|
4
|
+
data.tar.gz: 06d592a99720bd98c0752ba34ebb69f704952fba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d2c39d6619c345d9655f997158e3b56b5b8741c3323a1915023770976bf843b3e03f29d55d19cb126e48c1e44d802bd8f770b12fd694b77a70c51f763be85ea
|
7
|
+
data.tar.gz: d3291d91ccee3cfe7b9328f6b264b3a83dc12710510e6409443a7b0d219c165f8f250d66a2470de4fc589a6851be5d83a42a164aa80d450e752b1bb83267ccfe
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# BaconExpect
|
1
|
+
# BaconExpect [](https://travis-ci.org/ijpiantanida/bacon-expect) [](https://codeclimate.com/github/ijpiantanida/bacon-expect)
|
2
2
|
|
3
3
|
Bring [RSpec 3.0 expect syntax](https://www.relishapp.com/rspec/rspec-expectations/v/3-0/docs/built-in-matchers) to RubyMotion's MacBacon.
|
4
4
|
```ruby
|
data/bacon-expect.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "bacon-expect"
|
7
|
-
spec.version = "1.0.
|
7
|
+
spec.version = "1.0.3"
|
8
8
|
spec.authors = ["Ignacio Piantanida"]
|
9
9
|
spec.email = ["ijpiantanida@gmail.com"]
|
10
10
|
spec.description = "RSpec's expect syntax in MacBacon"
|
@@ -12,12 +12,12 @@ module BaconExpect
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def to(matcher)
|
15
|
-
fail(matcher) unless matcher_passes(matcher)
|
15
|
+
fail(matcher, false) unless matcher_passes(matcher)
|
16
16
|
assert
|
17
17
|
end
|
18
18
|
|
19
19
|
def not_to(matcher)
|
20
|
-
fail(matcher) if matcher_passes(matcher)
|
20
|
+
fail(matcher, true) if matcher_passes(matcher)
|
21
21
|
assert
|
22
22
|
end
|
23
23
|
alias_method :to_not, :not_to
|
@@ -26,8 +26,8 @@ module BaconExpect
|
|
26
26
|
matcher.matches?(@subject, &@subject_block)
|
27
27
|
end
|
28
28
|
|
29
|
-
def fail(matcher)
|
30
|
-
raise matcher.fail!(@subject, &@subject_block)
|
29
|
+
def fail(matcher, negated)
|
30
|
+
raise matcher.fail!(@subject, negated, &@subject_block)
|
31
31
|
end
|
32
32
|
|
33
33
|
def assert
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module BaconExpect
|
2
|
+
class FailMessageRenderer
|
3
|
+
def self.expectation(negated)
|
4
|
+
"#{negated ? " not" : ""} expected"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.message_for_be_false(negated, subject)
|
8
|
+
"#{subject.inspect}#{expectation(negated)} to be false"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.message_for_be_true(negated, subject)
|
12
|
+
"#{subject.inspect}#{expectation(negated)} to be true"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.message_for_be_nil(negated, subject)
|
16
|
+
"#{subject.inspect}#{expectation(negated)} to be nil"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.message_for_be(negated, subject, method_name, values)
|
20
|
+
message = "#{subject.inspect} ##{method_name}"
|
21
|
+
message += "(#{values.map(&:inspect).join(', ')})" unless values.empty?
|
22
|
+
message += "#{expectation(negated)} to return true"
|
23
|
+
message
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.message_for_be_within(negated, subject, range, center_value)
|
27
|
+
"#{subject.inspect}#{expectation(negated)} to be within #{range} of #{center_value}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.message_for_change(negated, change_amount, value_diff)
|
31
|
+
message = "Block#{expectation(negated)} to change value"
|
32
|
+
message += " by #{change_amount}" if change_amount
|
33
|
+
message += " but changed by #{value_diff}" if change_amount && !negated
|
34
|
+
message
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.message_for_end_with(negated, subject, end_string)
|
38
|
+
"#{subject.inspect}#{expectation(negated)} to end with #{end_string.inspect}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.message_for_start_with(negated, subject, start_string)
|
42
|
+
"#{subject.inspect}#{expectation(negated)} to start with #{start_string.inspect}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.message_for_be_equal(negated, subject, value)
|
46
|
+
"#{subject.inspect}#{expectation(negated)} to be same object as #{value.inspect}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.message_for_be_eq(negated, subject, value)
|
50
|
+
"#{subject.inspect}#{expectation(negated)} to be == to #{value.inspect}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.message_for_have_generic(negated, subject, method_name, values)
|
54
|
+
message = "#{subject.inspect} #has_#{method_name}?"
|
55
|
+
message += "(#{values.map(&:inspect).join(', ')})" unless values.empty?
|
56
|
+
message += "#{expectation(negated)} to return true"
|
57
|
+
message
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.message_for_have_items(negated, subject, expected_number_of_items, actual_number_of_items, key_type_name)
|
61
|
+
message = "#{subject.inspect}#{expectation(negated)} to have #{expected_number_of_items} #{key_type_name}"
|
62
|
+
message += " but had #{actual_number_of_items}" unless negated
|
63
|
+
message
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.message_for_include(negated, subject, values)
|
67
|
+
values_message = values.size == 1 ? values.first : values
|
68
|
+
message = "#{subject.inspect}#{expectation(negated)} to include #{values_message.inspect}"
|
69
|
+
message
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.message_for_match_array(negated, subject_array, expected_array)
|
73
|
+
message = "#{subject_array.inspect}#{expectation(negated)} to match array"
|
74
|
+
message += " #{expected_array.inspect}"
|
75
|
+
message
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.message_for_match(negated, subject, match)
|
79
|
+
"#{subject.inspect}#{expectation(negated)} to match #{match.inspect}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.message_for_raise_error(negated, show_class, error_class, show_message, error_message, rescued_exception)
|
83
|
+
message = "Block#{expectation(negated)} to raise error"
|
84
|
+
message += " of type #{error_class}" if show_class
|
85
|
+
message += " with message matching #{error_message.inspect}" if show_message
|
86
|
+
message += " but was #{rescued_exception.inspect}" if rescued_exception && !negated
|
87
|
+
message
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.message_for_respond_to(negated, subject, method_name, number_of_args)
|
91
|
+
message = "#{subject.inspect}#{expectation(negated)} to respond to ##{method_name}"
|
92
|
+
message += " with #{number_of_args} arguments" if number_of_args
|
93
|
+
message
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.message_for_satisfy(negated)
|
97
|
+
"Block#{expectation(negated)} to satisfy condition"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
module BaconExpect; module Matcher
|
2
|
-
class Be
|
2
|
+
class Be < SingleMethod
|
3
3
|
def initialize(value)
|
4
|
-
|
4
|
+
super(:equal?, value)
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def fail!(subject)
|
12
|
-
raise FailedExpectation.new("#{subject} expected to be equal? to #{@value}")
|
7
|
+
def fail_message(subject, negated)
|
8
|
+
FailMessageRenderer.message_for_be_equal(negated, subject, @values.first)
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end; end
|
@@ -4,8 +4,9 @@ module BaconExpect; module Matcher
|
|
4
4
|
!value
|
5
5
|
end
|
6
6
|
|
7
|
-
def fail!(subject)
|
8
|
-
|
7
|
+
def fail!(subject, negated)
|
8
|
+
message = FailMessageRenderer.message_for_be_false(negated, subject)
|
9
|
+
raise FailedExpectation.new(message)
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end; end
|
@@ -1,19 +1,7 @@
|
|
1
1
|
module BaconExpect; module Matcher
|
2
|
-
class BeGeneric
|
3
|
-
def initialize(method_name, *
|
4
|
-
|
5
|
-
@args = args
|
6
|
-
end
|
7
|
-
|
8
|
-
def matches?(value)
|
9
|
-
value.send("#{@method_name}?", *@args)
|
10
|
-
end
|
11
|
-
|
12
|
-
def fail!(subject)
|
13
|
-
message = "#{subject} expected to be #{@method_name}"
|
14
|
-
message += " with #{@args}" unless @args.empty?
|
15
|
-
message += " to return true"
|
16
|
-
raise FailedExpectation.new(message)
|
2
|
+
class BeGeneric < SingleMethod
|
3
|
+
def initialize(method_name, *values)
|
4
|
+
super("#{method_name}?", *values)
|
17
5
|
end
|
18
6
|
end
|
19
7
|
end; end
|
@@ -4,8 +4,8 @@ module BaconExpect; module Matcher
|
|
4
4
|
value == nil
|
5
5
|
end
|
6
6
|
|
7
|
-
def fail!(subject)
|
8
|
-
raise FailedExpectation.new(
|
7
|
+
def fail!(subject, negated)
|
8
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_be_nil(negated, subject))
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end; end
|
@@ -4,8 +4,8 @@ module BaconExpect; module Matcher
|
|
4
4
|
value == true
|
5
5
|
end
|
6
6
|
|
7
|
-
def fail!(subject)
|
8
|
-
raise FailedExpectation.new(
|
7
|
+
def fail!(subject, negated)
|
8
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_be_true(negated, subject))
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end; end
|
@@ -14,8 +14,8 @@ module BaconExpect; module Matcher
|
|
14
14
|
(subject - @center_value).abs <= @range
|
15
15
|
end
|
16
16
|
|
17
|
-
def fail!(subject)
|
18
|
-
raise FailedExpectation.new(
|
17
|
+
def fail!(subject, negated)
|
18
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_be_within(negated, subject, @range, @center_value))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end; end
|
@@ -14,16 +14,15 @@ module BaconExpect; module Matcher
|
|
14
14
|
expectation_block.call
|
15
15
|
new_value = @change_block.call
|
16
16
|
if @change_amount
|
17
|
-
new_value -
|
17
|
+
@value_diff = new_value - old_value
|
18
|
+
@value_diff == @change_amount
|
18
19
|
else
|
19
20
|
new_value != old_value
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
def fail!(subject)
|
24
|
-
|
25
|
-
message += " by #{@change_amount}" if @change_amount
|
26
|
-
raise FailedExpectation.new(message)
|
24
|
+
def fail!(subject, negated)
|
25
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_change(negated, @change_amount, @value_diff))
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end; end
|
@@ -8,8 +8,8 @@ module BaconExpect; module Matcher
|
|
8
8
|
subject[-@end_string.size..-1] == @end_string
|
9
9
|
end
|
10
10
|
|
11
|
-
def fail!(subject)
|
12
|
-
raise FailedExpectation.new(
|
11
|
+
def fail!(subject, negated)
|
12
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_end_with(negated, subject, @end_string))
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end; end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
module BaconExpect; module Matcher
|
2
|
-
class Eq
|
2
|
+
class Eq < SingleMethod
|
3
3
|
def initialize(value)
|
4
|
-
|
4
|
+
super(:==, value)
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
subject
|
9
|
-
end
|
10
|
-
|
11
|
-
def fail!(subject)
|
12
|
-
raise FailedExpectation.new("#{subject} expected to be == to #{@value}")
|
7
|
+
def fail_message(subject, negated)
|
8
|
+
FailMessageRenderer.message_for_be_eq(negated, subject, @values.first)
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end; end
|
@@ -1,15 +1,7 @@
|
|
1
1
|
module BaconExpect; module Matcher
|
2
|
-
class Eql
|
2
|
+
class Eql < SingleMethod
|
3
3
|
def initialize(value)
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
def matches?(subject)
|
8
|
-
subject.eql?(@value)
|
9
|
-
end
|
10
|
-
|
11
|
-
def fail!(subject)
|
12
|
-
raise FailedExpectation.new("#{subject} expected to be eql? to #{@value}")
|
4
|
+
super(:eql?, value)
|
13
5
|
end
|
14
6
|
end
|
15
7
|
end; end
|
@@ -9,11 +9,8 @@ module BaconExpect; module Matcher
|
|
9
9
|
subject.send("has_#{@method_name}?", *@args)
|
10
10
|
end
|
11
11
|
|
12
|
-
def fail!(subject)
|
13
|
-
|
14
|
-
message += " with #{@args}" unless @args.empty?
|
15
|
-
message += " to return true"
|
16
|
-
raise FailedExpectation.new(message)
|
12
|
+
def fail!(subject, negated)
|
13
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_have_generic(negated, subject, @method_name, @args))
|
17
14
|
end
|
18
15
|
end
|
19
16
|
end; end
|
@@ -8,15 +8,15 @@ module BaconExpect; module Matcher
|
|
8
8
|
value.size == @number_of_items
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
[:items, :item, :keys, :values].each do |key_type_name|
|
12
|
+
define_method(key_type_name) do
|
13
|
+
@key_type_name = key_type_name
|
14
|
+
self
|
15
|
+
end
|
13
16
|
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def fail!(subject)
|
19
|
-
raise FailedExpectation.new("#{subject} expected to have #{@number_of_items} items")
|
18
|
+
def fail!(subject, negated)
|
19
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_have_items(negated, subject, @number_of_items, subject.size, @key_type_name))
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end; end
|
@@ -8,8 +8,8 @@ module BaconExpect; module Matcher
|
|
8
8
|
@values.all?{|v| subject.include?(v)}
|
9
9
|
end
|
10
10
|
|
11
|
-
def fail!(subject)
|
12
|
-
raise FailedExpectation.new(
|
11
|
+
def fail!(subject, negated)
|
12
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_include(negated, subject, @values))
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end; end
|
@@ -1,15 +1,11 @@
|
|
1
1
|
module BaconExpect; module Matcher
|
2
|
-
class Match
|
3
|
-
def initialize(
|
4
|
-
|
2
|
+
class Match < SingleMethod
|
3
|
+
def initialize(value)
|
4
|
+
super(:match, value)
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def fail!(subject)
|
12
|
-
raise FailedExpectation.new("\"#{subject}\" expected to match #{@regex}")
|
7
|
+
def fail_message(subject, negated)
|
8
|
+
FailMessageRenderer.message_for_match(negated, subject, @values.first)
|
13
9
|
end
|
14
10
|
end
|
15
11
|
end; end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
module BaconExpect; module Matcher
|
2
2
|
class MatchArray
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(expected_array)
|
4
|
+
@expected_array = expected_array
|
5
5
|
end
|
6
6
|
|
7
7
|
def matches?(subject_array)
|
8
|
-
return false unless subject_array.size == @
|
8
|
+
return false unless subject_array.size == @expected_array.size
|
9
9
|
array_copy = subject_array.dup
|
10
|
-
@
|
10
|
+
@expected_array.all? do |item|
|
11
11
|
has = array_copy.include?(item)
|
12
12
|
array_copy.delete(item) if has
|
13
13
|
has
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def fail!(subject_array)
|
18
|
-
raise FailedExpectation.new(
|
17
|
+
def fail!(subject_array, negated)
|
18
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_match_array(negated, subject_array, @expected_array))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end; end
|
@@ -22,10 +22,10 @@ module BaconExpect; module Matcher
|
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
25
|
-
def fail!(subject)
|
26
|
-
|
27
|
-
|
28
|
-
raise FailedExpectation.new(
|
25
|
+
def fail!(subject, negated)
|
26
|
+
show_class = @error_class != Exception
|
27
|
+
show_message = !@error_message.is_a?(String) || !@error_message.empty?
|
28
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_raise_error(negated, show_class, @error_class, show_message, @error_message, @rescued_exception))
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end; end
|
@@ -21,8 +21,8 @@ module BaconExpect; module Matcher
|
|
21
21
|
valid
|
22
22
|
end
|
23
23
|
|
24
|
-
def fail!(subject)
|
25
|
-
raise FailedExpectation.new(
|
24
|
+
def fail!(subject, negated)
|
25
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_respond_to(negated, subject, @method_name, @number_of_args))
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end; end
|
@@ -8,8 +8,8 @@ module BaconExpect; module Matcher
|
|
8
8
|
@condition_block.call(*values)
|
9
9
|
end
|
10
10
|
|
11
|
-
def fail!(subject)
|
12
|
-
raise FailedExpectation.new(
|
11
|
+
def fail!(subject, negated)
|
12
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_satisfy(negated))
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end; end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BaconExpect; module Matcher
|
2
|
+
class SingleMethod
|
3
|
+
def initialize(method_name, *values)
|
4
|
+
@values = values
|
5
|
+
@method_name = method_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(subject)
|
9
|
+
subject.send(@method_name, *@values)
|
10
|
+
end
|
11
|
+
|
12
|
+
def fail!(subject, negated)
|
13
|
+
raise FailedExpectation.new(self.fail_message(subject, negated))
|
14
|
+
end
|
15
|
+
|
16
|
+
def fail_message(subject, negated = false)
|
17
|
+
FailMessageRenderer.message_for_be(negated, subject, @method_name, @values)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end; end
|
@@ -8,8 +8,8 @@ module BaconExpect; module Matcher
|
|
8
8
|
subject[0...@start_string.size] == @start_string
|
9
9
|
end
|
10
10
|
|
11
|
-
def fail!(subject)
|
12
|
-
raise FailedExpectation.new(
|
11
|
+
def fail!(subject, negated)
|
12
|
+
raise FailedExpectation.new(FailMessageRenderer.message_for_start_with(negated, subject, @start_string))
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end; end
|
data/run-tests.sh
ADDED
@@ -4,15 +4,16 @@ describe "Matcher::BeFalse" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "be_false fails when value is true" do
|
7
|
-
expect_failure{ expect(true).to be_false }
|
7
|
+
expect_failure("true expected to be false"){ expect(true).to be_false }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "be_false fails when value is an Object" do
|
11
|
-
|
11
|
+
object = Object.new
|
12
|
+
expect_failure("#{object} expected to be false"){ expect(object).to be_false }
|
12
13
|
end
|
13
14
|
|
14
15
|
it "be_false fails when value is false but asked for not_to" do
|
15
|
-
expect_failure{ expect(false).not_to be_false }
|
16
|
+
expect_failure("false not expected to be false"){ expect(false).not_to be_false }
|
16
17
|
end
|
17
18
|
|
18
19
|
it "be_false passes when value is true but asked for not_to" do
|
@@ -4,7 +4,7 @@ describe "Matcher::BeGeneric" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "be_empty fails when value is not empty" do
|
7
|
-
expect_failure{ expect([2, 3]).to be_empty }
|
7
|
+
expect_failure("[2, 3] #empty? expected to return true"){ expect([2, 3]).to be_empty }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "be_kind_of passes when value is of the given type" do
|
@@ -12,7 +12,7 @@ describe "Matcher::BeGeneric" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "be_kind_of fails when value is not of the given type" do
|
15
|
-
expect_failure{ expect("i'm a string").to be_kind_of(TrueClass) }
|
15
|
+
expect_failure("\"i'm a string\" #kind_of?(TrueClass) expected to return true"){ expect("i'm a string").to be_kind_of(TrueClass) }
|
16
16
|
end
|
17
17
|
|
18
18
|
it "be_amazing passes when the value responds to amazing? and returns true" do
|
@@ -22,6 +22,7 @@ describe "Matcher::BeGeneric" do
|
|
22
22
|
|
23
23
|
it "be_amazing fails when the value responds to amazing? and returns false" do
|
24
24
|
class TestClass; def amazing?; false; end; end
|
25
|
-
|
25
|
+
object = TestClass.new
|
26
|
+
expect_failure("#{object.inspect} #amazing? expected to return true"){ expect(object).to be_amazing }
|
26
27
|
end
|
27
28
|
end
|
@@ -4,14 +4,19 @@ describe "Matcher::BeNil" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "be_nil fails when value is true" do
|
7
|
-
expect_failure{ expect(true).to be_nil }
|
7
|
+
expect_failure("true expected to be nil"){ expect(true).to be_nil }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "be_nil fails when value is false" do
|
11
|
-
expect_failure{ expect(false).to be_nil }
|
11
|
+
expect_failure("false expected to be nil"){ expect(false).to be_nil }
|
12
12
|
end
|
13
13
|
|
14
14
|
it "be_nil fails when value is an Object" do
|
15
|
-
|
15
|
+
object = Object.new
|
16
|
+
expect_failure("#{object} expected to be nil"){ expect(object).to be_nil }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "be_nil fails when value is nil but asked not to" do
|
20
|
+
expect_failure("nil not expected to be nil"){ expect(nil).not_to be_nil }
|
16
21
|
end
|
17
22
|
end
|
@@ -4,15 +4,16 @@ describe "Matcher::BeTrue" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "be_true fails when value is false" do
|
7
|
-
expect_failure{ expect(false).to be_true }
|
7
|
+
expect_failure("false expected to be true"){ expect(false).to be_true }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "be_true fails when value is an Object" do
|
11
|
-
|
11
|
+
object = Object.new
|
12
|
+
expect_failure("#{object} expected to be true"){ expect(object).to be_true }
|
12
13
|
end
|
13
14
|
|
14
15
|
it "be_true fails when value is true but asked for not_to" do
|
15
|
-
expect_failure{ expect(true).not_to be_true }
|
16
|
+
expect_failure("true not expected to be true"){ expect(true).not_to be_true }
|
16
17
|
end
|
17
18
|
|
18
19
|
it "be_true passes when value is false but asked for not_to" do
|
@@ -9,10 +9,10 @@ describe "Matcher::BeWithin" do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "fails when subject is not within range" do
|
12
|
-
expect_failure{ expect(27.5).not_to be_within(0.5).of(28) }
|
13
|
-
expect_failure{ expect(27.5).not_to be_within(0.5).of(27) }
|
14
|
-
expect_failure{ expect(27.5).to be_within(0.5).of(28.
|
15
|
-
expect_failure{ expect(27.5).to be_within(0.5).of(26.
|
12
|
+
expect_failure("27.5 not expected to be within 0.5 of 28"){ expect(27.5).not_to be_within(0.5).of(28) }
|
13
|
+
expect_failure("27.5 not expected to be within 0.5 of 27"){ expect(27.5).not_to be_within(0.5).of(27) }
|
14
|
+
expect_failure("27.5 expected to be within 0.5 of 28.5"){ expect(27.5).to be_within(0.5).of(28.5) }
|
15
|
+
expect_failure("27.5 expected to be within 0.5 of 26.5"){ expect(27.5).to be_within(0.5).of(26.5) }
|
16
16
|
end
|
17
17
|
|
18
18
|
it "raises an exception when the matcher is not complete" do
|
@@ -19,7 +19,7 @@ describe "Matcher::Change" do
|
|
19
19
|
|
20
20
|
it "change fails when the expected block doesn't change the result of the argument block" do
|
21
21
|
test_object = TestClass.new
|
22
|
-
expect_failure{ expect{ test_object.dont_add }.to change{ test_object.counter } }
|
22
|
+
expect_failure("Block expected to change value"){ expect{ test_object.dont_add }.to change{ test_object.counter } }
|
23
23
|
end
|
24
24
|
|
25
25
|
it "change passes when the expected block doesn't change the result of the argument block but asked not_to" do
|
@@ -34,6 +34,11 @@ describe "Matcher::Change" do
|
|
34
34
|
|
35
35
|
it "change when specified 'by' fails when the expected block changes the result of the argument block by a different amount" do
|
36
36
|
test_object = TestClass.new
|
37
|
-
expect_failure{ expect{ test_object.add; test_object.add }.to change{ test_object.counter }.by(6) }
|
37
|
+
expect_failure("Block expected to change value by 6 but changed by 2"){ expect{ test_object.add; test_object.add }.to change{ test_object.counter }.by(6) }
|
38
|
+
end
|
39
|
+
|
40
|
+
it "change when specified 'by' fails when the expected block changes the result of the argument block by the given amount but asked not to" do
|
41
|
+
test_object = TestClass.new
|
42
|
+
expect_failure("Block not expected to change value by 2"){ expect{ test_object.add; test_object.add }.not_to change{ test_object.counter }.by(2) }
|
38
43
|
end
|
39
44
|
end
|
@@ -4,6 +4,10 @@ describe "Matcher::EndWith" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "end_with fails when the subject doesn't end with the given string" do
|
7
|
-
expect_failure{ expect("super").to end_with("key") }
|
7
|
+
expect_failure("\"super\" expected to end with \"key\""){ expect("super").to end_with("key") }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "end_with fails when the subject ends with the given string but asked to not" do
|
11
|
+
expect_failure("\"super\" not expected to end with \"per\""){ expect("super").not_to end_with("per") }
|
8
12
|
end
|
9
13
|
end
|
@@ -4,7 +4,7 @@ describe "Matcher::Equality" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "eql fails when value is not eql? subject" do
|
7
|
-
expect_failure{ expect(1).to eql(1.0) }
|
7
|
+
expect_failure("1 #eql?(1.0) expected to return true"){ expect(1).to eql(1.0) }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "eq passes if value is == to subject" do
|
@@ -12,7 +12,7 @@ describe "Matcher::Equality" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "eq fails if value is == to subject" do
|
15
|
-
expect_failure{ expect(1).to eq(2.0) }
|
15
|
+
expect_failure("1 expected to be == to 2.0"){ expect(1).to eq(2.0) }
|
16
16
|
end
|
17
17
|
|
18
18
|
it "be passes if value is same object as subject" do
|
@@ -21,10 +21,17 @@ describe "Matcher::Equality" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "be fails if value is not the same object as subject" do
|
24
|
-
expect_failure{ expect("super").to be("super") }
|
24
|
+
expect_failure("\"super\" expected to be same object as \"super\""){ expect("super").to be("super") }
|
25
25
|
end
|
26
26
|
|
27
27
|
it "equal fails if value is not the same object as subject" do
|
28
|
-
expect_failure{ expect("super").to equal("super") }
|
28
|
+
expect_failure("\"super\" expected to be same object as \"super\""){ expect("super").to equal("super") }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "equal fails if value is the same object as subject but asked not to" do
|
32
|
+
expect_failure("\"super\" not expected to be same object as \"super\"") do
|
33
|
+
string = "super"
|
34
|
+
expect(string).not_to equal(string)
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
@@ -4,7 +4,7 @@ describe "Matcher::HaveGeneric" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "have_key fails if the hash doesn't include the given key" do
|
7
|
-
expect_failure{ expect({a: 1, b: 2, c: 3}).to have_key(:h) }
|
7
|
+
expect_failure("{:a=>1, :b=>2, :c=>3} #has_key?(:h) expected to return true"){ expect({a: 1, b: 2, c: 3}).to have_key(:h) }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "have_color passes when the value responds to has_color? and returns true" do
|
@@ -14,6 +14,13 @@ describe "Matcher::HaveGeneric" do
|
|
14
14
|
|
15
15
|
it "have_color fails when the value responds to has_color? and returns false" do
|
16
16
|
class TestClass; def has_color?(color); color == :red; end; end
|
17
|
-
|
17
|
+
object = TestClass.new
|
18
|
+
expect_failure("#{object.inspect} #has_color?(:blue) expected to return true"){ expect(object).to have_color(:blue) }
|
19
|
+
end
|
20
|
+
|
21
|
+
it "have_color fails when the value responds to has_color? and returns true but asked not to" do
|
22
|
+
class TestClass; def has_color?(color); color == :red; end; end
|
23
|
+
object = TestClass.new
|
24
|
+
expect_failure("#{object.inspect} #has_color?(:red) not expected to return true"){ expect(object).to_not have_color(:red) }
|
18
25
|
end
|
19
26
|
end
|
@@ -4,6 +4,14 @@ describe "Matcher::HaveItems" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it 'have fails when subject has the a different number of items' do
|
7
|
-
expect_failure{ expect([1,2,3]).to have(10).items }
|
7
|
+
expect_failure("[1, 2, 3] expected to have 10 items but had 3"){ expect([1,2,3]).to have(10).items }
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'have fails when subject has the same number of items but asked not to' do
|
11
|
+
expect_failure("[1, 2, 3] not expected to have 3 items"){ expect([1,2,3]).not_to have(3).items }
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'have failure message changes when sending #keys instead of #items' do
|
15
|
+
expect_failure("[1, 2, 3] not expected to have 3 keys"){ expect([1,2,3]).not_to have(3).keys }
|
8
16
|
end
|
9
17
|
end
|
@@ -4,7 +4,7 @@ describe "Matcher::Include" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it 'include fails when subject include? responds false' do
|
7
|
-
expect_failure{ expect([1,2,3,4]).to include("asd") }
|
7
|
+
expect_failure("[1, 2, 3, 4] expected to include \"asd\""){ expect([1,2,3,4]).to include("asd") }
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'include passes when an object responds true to include?' do
|
@@ -14,7 +14,8 @@ describe "Matcher::Include" do
|
|
14
14
|
|
15
15
|
it 'include passes when an object responds false to include?' do
|
16
16
|
class TestClass; def include?(value); false; end; end
|
17
|
-
|
17
|
+
test_object = TestClass.new
|
18
|
+
expect_failure("#{test_object.inspect} expected to include 3"){ expect(test_object).to include(3) }
|
18
19
|
end
|
19
20
|
|
20
21
|
it "include passes when all values are included in subject" do
|
@@ -22,6 +23,10 @@ describe "Matcher::Include" do
|
|
22
23
|
end
|
23
24
|
|
24
25
|
it "include fails when some values are not included in subject" do
|
25
|
-
expect_failure{ expect([1,2,3,4]).to include(2,3,4, 6) }
|
26
|
+
expect_failure("#{[1,2,3,4]} expected to include #{[2, 3, 4, 6]}"){ expect([1,2,3,4]).to include(2, 3, 4, 6) }
|
27
|
+
end
|
28
|
+
|
29
|
+
it "include fails when all values are included but asked not to" do
|
30
|
+
expect_failure("#{[1,2,3,4,5,6]} not expected to include #{[3, 4, 6]}"){ expect([1,2,3,4,5,6]).not_to include(3, 4, 6) }
|
26
31
|
end
|
27
32
|
end
|
@@ -4,14 +4,19 @@ describe "Matcher::MatchArray" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "match_array fails when subject has less items than value" do
|
7
|
-
expect_failure{ expect([1,2,3]).to match_array([1,2,3,4]) }
|
7
|
+
expect_failure("#{[1,2,3]} expected to match array #{[1,2,3,4]}"){ expect([1,2,3]).to match_array([1,2,3,4]) }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "match_array fails when subject has more items than value" do
|
11
|
-
expect_failure{ expect([1,2,3,4]).to match_array([1,2,4,4,3]) }
|
11
|
+
expect_failure("#{[1,2,3, 4]} expected to match array #{[1,2,4,4,3]}"){ expect([1,2,3,4]).to match_array([1,2,4,4,3]) }
|
12
12
|
end
|
13
13
|
|
14
14
|
it "match_array fails when subject has different items" do
|
15
|
-
|
15
|
+
expected_array = [Object.new, "a", 2, 3]
|
16
|
+
expect_failure("#{[1,2,3,4]} expected to match array #{expected_array}"){ expect([1,2,3,4]).to match_array(expected_array) }
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'match_array fails when subject matches the array but asked not to' do
|
20
|
+
expect_failure("#{[1,2,3,4]} not expected to match array"){ expect([1,2,3,4]).to_not match_array([4,2,1,3]) }
|
16
21
|
end
|
17
22
|
end
|
@@ -4,7 +4,7 @@ describe "Matcher::Match" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "match fails when subject is a string and doesn't match the regex" do
|
7
|
-
expect_failure{ expect("qwerty qwerty").to match(/asd/) }
|
7
|
+
expect_failure("\"qwerty qwerty\" expected to match /asd/"){ expect("qwerty qwerty").to match(/asd/) }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "match passes when subject is a regex and matches the given string" do
|
@@ -12,6 +12,10 @@ describe "Matcher::Match" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "match fails when subject is a regex and doesn't matche the given string" do
|
15
|
-
expect_failure{ expect(/foo/).to match("drink") }
|
15
|
+
expect_failure("/foo/ expected to match \"drink\""){ expect(/foo/).to match("drink") }
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'match fails when subject is a string and matches the regex but asked not to' do
|
19
|
+
expect_failure("\"asd asd asd\" not expected to match /asd/"){ expect("asd asd asd").to_not match(/asd/) }
|
16
20
|
end
|
17
21
|
end
|
@@ -4,7 +4,7 @@ describe "Matcher::RaiseError" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "raise_error without argument failes when the block doesn't raise any exception" do
|
7
|
-
expect_failure{ expect{ Object.new }.to raise_error }
|
7
|
+
expect_failure("Block expected to raise error"){ expect{ Object.new }.to raise_error }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "raise_error with a class argument passes when the block raises an exception of the argument class" do
|
@@ -12,7 +12,7 @@ describe "Matcher::RaiseError" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "raise_error with a class argument fails when the block raises an exception of a different class" do
|
15
|
-
expect_failure{ expect{ 1/0 }.to raise_error(ArgumentError) }
|
15
|
+
expect_failure("Block expected to raise error of type ArgumentError"){ expect{ 1/0 }.to raise_error(ArgumentError) }
|
16
16
|
end
|
17
17
|
|
18
18
|
it "raise_error with a string argument passes when the block raises an exception with a message that includes the string" do
|
@@ -20,7 +20,7 @@ describe "Matcher::RaiseError" do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "raise_error with a string argument fails when the block raises an exception with a message that doesn't include the string" do
|
23
|
-
expect_failure{ expect{ raise "one message" }.to raise_error("different") }
|
23
|
+
expect_failure("Block expected to raise error with message matching \"different\" but was #<RuntimeError: one message>"){ expect{ raise "one message" }.to raise_error("different") }
|
24
24
|
end
|
25
25
|
|
26
26
|
it "raise_error with a Regex argument passes when the block raises an exception with a message that matches the Regex" do
|
@@ -28,7 +28,7 @@ describe "Matcher::RaiseError" do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "raise_error with a Regex argument fails when the block raises an exception with a message that doesn't match the Regex" do
|
31
|
-
expect_failure{ expect{ raise "one message" }.to raise_error(/different/) }
|
31
|
+
expect_failure("Block expected to raise error with message matching #{/different/.inspect} but was #<RuntimeError: one message>"){ expect{ raise "one message" }.to raise_error(/different/) }
|
32
32
|
end
|
33
33
|
|
34
34
|
it "raise_error with a class and a string argument passes if the block raises an exception of the same class and includes the string in its message" do
|
@@ -36,11 +36,11 @@ describe "Matcher::RaiseError" do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "raise_error with a class and a string argument fails if the block raises an exception of the same class and but doesn't include the string in its message" do
|
39
|
-
expect_failure{ expect{ raise ArgumentError.new("with a message") }.to raise_error(ArgumentError, "different") }
|
39
|
+
expect_failure("Block expected to raise error of type ArgumentError with message matching #{"different".inspect}"){ expect{ raise ArgumentError.new("with a message") }.to raise_error(ArgumentError, "different") }
|
40
40
|
end
|
41
41
|
|
42
42
|
it "raise_error with a class and a string argument fails if the block raises an exception of a different class" do
|
43
|
-
expect_failure{ expect{ raise ArgumentError.new("with a message") }.to raise_error(ZeroDivisionError, "message") }
|
43
|
+
expect_failure("Block expected to raise error of type ZeroDivisionError with message matching #{"message".inspect}"){ expect{ raise ArgumentError.new("with a message") }.to raise_error(ZeroDivisionError, "message") }
|
44
44
|
end
|
45
45
|
|
46
46
|
it "raise_error with a class and a regex argument passes if the block raises an exception of the same class and includes the string in its message" do
|
@@ -48,14 +48,18 @@ describe "Matcher::RaiseError" do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "raise_error with a class and a regex argument fails if the block raises an exception of the same class and but doesn't include the string in its message" do
|
51
|
-
expect_failure{ expect{ raise ArgumentError.new("with a message") }.to raise_error(ArgumentError, /different/) }
|
51
|
+
expect_failure("Block expected to raise error of type ArgumentError with message matching #{/different/.inspect}"){ expect{ raise ArgumentError.new("with a message") }.to raise_error(ArgumentError, /different/) }
|
52
52
|
end
|
53
53
|
|
54
54
|
it "raise_error with a class and a regex argument fails if the block raises an exception of a different class" do
|
55
|
-
expect_failure{ expect{ raise ArgumentError.new("with a message") }.to raise_error(ZeroDivisionError, /message/) }
|
55
|
+
expect_failure("Block expected to raise error of type ZeroDivisionError with message matching #{/message/.inspect} but was "){ expect{ raise ArgumentError.new("with a message") }.to raise_error(ZeroDivisionError, /message/) }
|
56
56
|
end
|
57
57
|
|
58
58
|
it "raise_exception is an alias of raise_error " do
|
59
59
|
expect{ 1/0 }.to raise_exception(ZeroDivisionError)
|
60
60
|
end
|
61
|
+
|
62
|
+
it "raise_error with a class argument fails when the block raises an exception of the argument class but asked not to" do
|
63
|
+
expect_failure("Block not expected to raise error of type ZeroDivisionError"){ expect{ 1/0 }.not_to raise_error(ZeroDivisionError) }
|
64
|
+
end
|
61
65
|
end
|
@@ -4,11 +4,11 @@ describe "Matcher::RespondTo" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "respond_to fails when subject doesn't respond to method name" do
|
7
|
-
expect_failure{ expect("string").to respond_to(:floor) }
|
7
|
+
expect_failure("\"string\" expected to respond to #floor"){ expect("string").to respond_to(:floor) }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "respond_to when given number of arguments fails when subject doesn't respond to method name" do
|
11
|
-
expect_failure{ expect("string").to respond_to(:floor).with(2).arguments }
|
11
|
+
expect_failure("\"string\" expected to respond to #floor with 2 arguments"){ expect("string").to respond_to(:floor).with(2).arguments }
|
12
12
|
end
|
13
13
|
|
14
14
|
it "respond_to when given number of arguments passes when subject responds to method name with exactly the same number of arguments" do
|
@@ -18,6 +18,13 @@ describe "Matcher::RespondTo" do
|
|
18
18
|
|
19
19
|
it "respond_to when given number of arguments fails when subject responds to method name with different number of arguments" do
|
20
20
|
class TestCase; def call_me(a,b,c); end; end
|
21
|
-
|
21
|
+
test_object = TestCase.new
|
22
|
+
expect_failure("#{test_object.inspect} expected to respond to #call_me with 1 arguments"){ expect(test_object).to respond_to(:call_me).with(1).argument }
|
23
|
+
end
|
24
|
+
|
25
|
+
it "respond_to when given number of arguments fails when subject responds to method name with exactly the same number of arguments but asked not to" do
|
26
|
+
class TestCase; def call_me(a,b,c); end; end
|
27
|
+
test_object = TestCase.new
|
28
|
+
expect_failure("#{test_object.inspect} not expected to respond to #call_me with 3 arguments"){ expect(test_object).not_to respond_to(:call_me).with(3).arguments }
|
22
29
|
end
|
23
30
|
end
|
@@ -4,10 +4,14 @@ describe "Matcher::Satisfy" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it 'satisfy fails when the block returns false' do
|
7
|
-
expect_failure{ expect(1).to satisfy{|v| v == 3} }
|
7
|
+
expect_failure("Block expected to satisfy condition"){ expect(1).to satisfy{|v| v == 3} }
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'satisfy fails when the block raises an exception' do
|
11
11
|
expect{ expect(1).to satisfy{|v| 1/0 } }.to raise_error(ZeroDivisionError)
|
12
12
|
end
|
13
|
+
|
14
|
+
it 'satisfy fails when the block returns true but asked not to' do
|
15
|
+
expect_failure("Block not expected to satisfy condition"){ expect(1).not_to satisfy{|v| v == 1} }
|
16
|
+
end
|
13
17
|
end
|
@@ -4,6 +4,10 @@ describe "Matcher::StartWith" do
|
|
4
4
|
end
|
5
5
|
|
6
6
|
it "start_with fails when the subject doesn't start with the given string" do
|
7
|
-
expect_failure{ expect("super").to start_with("key") }
|
7
|
+
expect_failure("\"super\" expected to start with \"key\""){ expect("super").to start_with("key") }
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'start_with fails when the subject starts with the given string but asked not to' do
|
11
|
+
expect_failure("\"super\" not expected to start with \"sup\""){ expect("super").to_not start_with("sup") }
|
8
12
|
end
|
9
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bacon-expect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ignacio Piantanida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- .gitignore
|
49
|
+
- .travis.yml
|
49
50
|
- Gemfile
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- lib/bacon-expect/bacon_context.rb
|
56
57
|
- lib/bacon-expect/exceptions.rb
|
57
58
|
- lib/bacon-expect/expectation.rb
|
59
|
+
- lib/bacon-expect/fail_message_renderer.rb
|
58
60
|
- lib/bacon-expect/matchers/be.rb
|
59
61
|
- lib/bacon-expect/matchers/be_false.rb
|
60
62
|
- lib/bacon-expect/matchers/be_generic.rb
|
@@ -74,7 +76,9 @@ files:
|
|
74
76
|
- lib/bacon-expect/matchers/raise_error.rb
|
75
77
|
- lib/bacon-expect/matchers/respond_to.rb
|
76
78
|
- lib/bacon-expect/matchers/satisfy.rb
|
79
|
+
- lib/bacon-expect/matchers/single_method.rb
|
77
80
|
- lib/bacon-expect/matchers/start_with.rb
|
81
|
+
- run-tests.sh
|
78
82
|
- spec_app/.repl_history
|
79
83
|
- spec_app/Gemfile
|
80
84
|
- spec_app/Rakefile
|