remarkable 3.1.8 → 3.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +58 -58
- data/LICENSE +20 -20
- data/README +197 -197
- data/lib/remarkable.rb +18 -18
- data/lib/remarkable/base.rb +55 -56
- data/lib/remarkable/core_ext/array.rb +19 -19
- data/lib/remarkable/dsl.rb +35 -35
- data/lib/remarkable/dsl/assertions.rb +384 -384
- data/lib/remarkable/dsl/callbacks.rb +52 -52
- data/lib/remarkable/dsl/optionals.rb +122 -122
- data/lib/remarkable/i18n.rb +53 -53
- data/lib/remarkable/macros.rb +48 -48
- data/lib/remarkable/matchers.rb +17 -17
- data/lib/remarkable/messages.rb +103 -103
- data/lib/remarkable/pending.rb +66 -66
- data/lib/remarkable/rspec.rb +24 -24
- data/lib/remarkable/version.rb +3 -3
- data/locale/en.yml +14 -14
- data/spec/base_spec.rb +41 -41
- data/spec/dsl/assertions_spec.rb +54 -54
- data/spec/dsl/optionals_spec.rb +237 -237
- data/spec/i18n_spec.rb +41 -41
- data/spec/locale/en.yml +20 -20
- data/spec/locale/pt-BR.yml +21 -21
- data/spec/macros_spec.rb +26 -26
- data/spec/matchers/be_a_person_matcher.rb +25 -25
- data/spec/matchers/collection_contain_matcher.rb +32 -32
- data/spec/matchers/contain_matcher.rb +31 -31
- data/spec/matchers/single_contain_matcher.rb +49 -49
- data/spec/matchers_spec.rb +5 -5
- data/spec/messages_spec.rb +66 -66
- data/spec/pending_spec.rb +7 -7
- data/spec/spec.opts +4 -4
- data/spec/spec_helper.rb +15 -15
- metadata +3 -3
data/lib/remarkable/rspec.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
module Spec #:nodoc:
|
2
|
-
module Matchers #:nodoc:
|
3
|
-
# Overwrites to provide I18n on should and should_not.
|
4
|
-
#
|
5
|
-
def self.generated_description
|
6
|
-
return nil if last_should.nil?
|
7
|
-
verb = Remarkable.t "remarkable.core.#{last_should}", :default => last_should.to_s.gsub('_',' ')
|
8
|
-
"#{verb} #{last_description}"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
module Example #:nodoc:
|
13
|
-
module ExampleGroupMethods #:nodoc:
|
14
|
-
# Overwrites to provide I18n on example disabled message.
|
15
|
-
#
|
16
|
-
def xexample(description=nil, opts={}, &block)
|
17
|
-
disabled = Remarkable.t 'remarkable.core.example_disabled', :default => 'Example disabled'
|
18
|
-
Kernel.warn("#{disabled}: #{description}")
|
19
|
-
end
|
20
|
-
alias_method :xit, :xexample
|
21
|
-
alias_method :xspecify, :xexample
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
module Spec #:nodoc:
|
2
|
+
module Matchers #:nodoc:
|
3
|
+
# Overwrites to provide I18n on should and should_not.
|
4
|
+
#
|
5
|
+
def self.generated_description
|
6
|
+
return nil if last_should.nil?
|
7
|
+
verb = Remarkable.t "remarkable.core.#{last_should}", :default => last_should.to_s.gsub('_',' ')
|
8
|
+
"#{verb} #{last_description}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Example #:nodoc:
|
13
|
+
module ExampleGroupMethods #:nodoc:
|
14
|
+
# Overwrites to provide I18n on example disabled message.
|
15
|
+
#
|
16
|
+
def xexample(description=nil, opts={}, &block)
|
17
|
+
disabled = Remarkable.t 'remarkable.core.example_disabled', :default => 'Example disabled'
|
18
|
+
Kernel.warn("#{disabled}: #{description}")
|
19
|
+
end
|
20
|
+
alias_method :xit, :xexample
|
21
|
+
alias_method :xspecify, :xexample
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/remarkable/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Remarkable
|
2
|
-
VERSION = '3.1.
|
3
|
-
end
|
1
|
+
module Remarkable
|
2
|
+
VERSION = '3.1.9' unless self.const_defined?(:VERSION)
|
3
|
+
end
|
data/locale/en.yml
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
en:
|
2
|
-
remarkable:
|
3
|
-
core:
|
4
|
-
not: "not"
|
5
|
-
should: "should"
|
6
|
-
should_not: "should not"
|
7
|
-
example_disabled: "Example disabled"
|
8
|
-
failure_message_for_should: "Expected {{expectation}}"
|
9
|
-
failure_message_for_should_not: "Did not expect {{expectation}}"
|
10
|
-
|
11
|
-
helpers:
|
12
|
-
words_connector: ", "
|
13
|
-
two_words_connector: " and "
|
14
|
-
last_word_connector: ", and "
|
1
|
+
en:
|
2
|
+
remarkable:
|
3
|
+
core:
|
4
|
+
not: "not"
|
5
|
+
should: "should"
|
6
|
+
should_not: "should not"
|
7
|
+
example_disabled: "Example disabled"
|
8
|
+
failure_message_for_should: "Expected {{expectation}}"
|
9
|
+
failure_message_for_should_not: "Did not expect {{expectation}}"
|
10
|
+
|
11
|
+
helpers:
|
12
|
+
words_connector: ", "
|
13
|
+
two_words_connector: " and "
|
14
|
+
last_word_connector: ", and "
|
data/spec/base_spec.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Remarkable::Base do
|
4
|
-
subject { [1, 2, 3] }
|
5
|
-
|
6
|
-
it 'should provide default structure to matchers' do
|
7
|
-
[1, 2, 3].should contain(1)
|
8
|
-
[1, 2, 3].should contain(1, 2)
|
9
|
-
[1, 2, 3].should contain(1, 2, 3)
|
10
|
-
|
11
|
-
[1, 2, 3].should_not contain(4)
|
12
|
-
[1, 2, 3].should_not contain(1, 4)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should not change rspec matchers default behavior' do
|
16
|
-
should include(3)
|
17
|
-
[1, 2, 3].should include(3)
|
18
|
-
|
19
|
-
1.should == 1
|
20
|
-
true.should be_true
|
21
|
-
false.should be_false
|
22
|
-
proc{ 1 + '' }.should raise_error(TypeError)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should store spec instance binding' do
|
26
|
-
matcher = contain(1)
|
27
|
-
should matcher
|
28
|
-
matcher.instance_variable_get('@spec').class.ancestors.should include(Spec::Example::ExampleGroup)
|
29
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Remarkable::Base do
|
4
|
+
subject { [1, 2, 3] }
|
5
|
+
|
6
|
+
it 'should provide default structure to matchers' do
|
7
|
+
[1, 2, 3].should contain(1)
|
8
|
+
[1, 2, 3].should contain(1, 2)
|
9
|
+
[1, 2, 3].should contain(1, 2, 3)
|
10
|
+
|
11
|
+
[1, 2, 3].should_not contain(4)
|
12
|
+
[1, 2, 3].should_not contain(1, 4)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should not change rspec matchers default behavior' do
|
16
|
+
should include(3)
|
17
|
+
[1, 2, 3].should include(3)
|
18
|
+
|
19
|
+
1.should == 1
|
20
|
+
true.should be_true
|
21
|
+
false.should be_false
|
22
|
+
proc{ 1 + '' }.should raise_error(TypeError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should store spec instance binding' do
|
26
|
+
matcher = contain(1)
|
27
|
+
should matcher
|
28
|
+
matcher.instance_variable_get('@spec').class.ancestors.should include(Spec::Example::ExampleGroup)
|
29
|
+
end
|
30
30
|
|
31
31
|
it 'should be positive' do
|
32
32
|
contain(1).should be_positive
|
33
33
|
contain(1).should_not be_negative
|
34
34
|
end
|
35
|
-
|
36
|
-
it { should contain(1) }
|
37
|
-
it { should_not contain(10) }
|
38
|
-
|
39
|
-
class MatchersSandbox
|
40
|
-
include Remarkable::Matchers
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should allow Macros and Matchers to be added to any class' do
|
44
|
-
MatchersSandbox.new.should respond_to(:contain)
|
45
|
-
end
|
46
|
-
end
|
35
|
+
|
36
|
+
it { should contain(1) }
|
37
|
+
it { should_not contain(10) }
|
38
|
+
|
39
|
+
class MatchersSandbox
|
40
|
+
include Remarkable::Matchers
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should allow Macros and Matchers to be added to any class' do
|
44
|
+
MatchersSandbox.new.should respond_to(:contain)
|
45
|
+
end
|
46
|
+
end
|
data/spec/dsl/assertions_spec.rb
CHANGED
@@ -1,54 +1,54 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Remarkable::DSL::Assertions do
|
4
|
-
subject { [1, 2, 3] }
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
@matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1, 2, 3)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should provide default structure for assertions' do
|
11
|
-
should collection_contain(1)
|
12
|
-
should collection_contain(1, 2)
|
13
|
-
should collection_contain(1, 2, 3)
|
14
|
-
|
15
|
-
should_not collection_contain(4)
|
16
|
-
should_not collection_contain(1, 4)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should provide default structure for single assertions' do
|
20
|
-
should single_contain(1)
|
21
|
-
should_not single_contain(4)
|
22
|
-
nil.should_not single_contain(1)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should provide collection in description' do
|
26
|
-
@matcher.description.should == 'contain 1, 2, and 3'
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should provide value to expectation messages' do
|
30
|
-
@matcher.matches?([4])
|
31
|
-
@matcher.failure_message.should == 'Expected that 1 is included in [4]'
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should accept blocks as argument' do
|
35
|
-
should_not single_contain(4)
|
36
|
-
should single_contain(4){ self << 4 }
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should provide an interface for default_options hook' do
|
40
|
-
matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1, :args => true)
|
41
|
-
matcher.instance_variable_get('@options').should == { :working => true, :args => true }
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should provide an interface for after_initialize hook' do
|
45
|
-
matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1)
|
46
|
-
matcher.instance_variable_get('@after_initialize').should be_true
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should provide an interface for before_assert hook' do
|
50
|
-
matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1)
|
51
|
-
[1, 2, 3].should matcher
|
52
|
-
matcher.instance_variable_get('@before_assert').should be_true
|
53
|
-
end
|
54
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Remarkable::DSL::Assertions do
|
4
|
+
subject { [1, 2, 3] }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1, 2, 3)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should provide default structure for assertions' do
|
11
|
+
should collection_contain(1)
|
12
|
+
should collection_contain(1, 2)
|
13
|
+
should collection_contain(1, 2, 3)
|
14
|
+
|
15
|
+
should_not collection_contain(4)
|
16
|
+
should_not collection_contain(1, 4)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should provide default structure for single assertions' do
|
20
|
+
should single_contain(1)
|
21
|
+
should_not single_contain(4)
|
22
|
+
nil.should_not single_contain(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should provide collection in description' do
|
26
|
+
@matcher.description.should == 'contain 1, 2, and 3'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should provide value to expectation messages' do
|
30
|
+
@matcher.matches?([4])
|
31
|
+
@matcher.failure_message.should == 'Expected that 1 is included in [4]'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should accept blocks as argument' do
|
35
|
+
should_not single_contain(4)
|
36
|
+
should single_contain(4){ self << 4 }
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should provide an interface for default_options hook' do
|
40
|
+
matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1, :args => true)
|
41
|
+
matcher.instance_variable_get('@options').should == { :working => true, :args => true }
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should provide an interface for after_initialize hook' do
|
45
|
+
matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1)
|
46
|
+
matcher.instance_variable_get('@after_initialize').should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should provide an interface for before_assert hook' do
|
50
|
+
matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1)
|
51
|
+
[1, 2, 3].should matcher
|
52
|
+
matcher.instance_variable_get('@before_assert').should be_true
|
53
|
+
end
|
54
|
+
end
|
data/spec/dsl/optionals_spec.rb
CHANGED
@@ -1,237 +1,237 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
-
|
4
|
-
describe Remarkable::DSL::Optionals do
|
5
|
-
|
6
|
-
describe "without config blocks" do
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
@matcher = Remarkable::Specs::Matchers::BeAPersonMatcher.new
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "as optionals" do
|
13
|
-
it "should allow optionals to be set" do
|
14
|
-
@matcher.first_name('José')
|
15
|
-
@matcher.options[:first_name].should == 'José'
|
16
|
-
|
17
|
-
@matcher.last_name('Valim')
|
18
|
-
@matcher.options[:last_name].should == 'Valim'
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should allow defaults values" do
|
22
|
-
@matcher.age
|
23
|
-
@matcher.options[:age].should == 18
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should allow alias to be set" do
|
27
|
-
@matcher.family_name('Valim')
|
28
|
-
@matcher.options[:last_name].should == 'Valim'
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should allow multiple options to be given" do
|
32
|
-
@matcher.bands(:incubus, :foo_fighters)
|
33
|
-
@matcher.options[:bands].should == [:incubus, :foo_fighters]
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should allow multiple options to be appended once at a time" do
|
37
|
-
@matcher.bands(:incubus)
|
38
|
-
@matcher.bands(:foo_fighters)
|
39
|
-
@matcher.options[:bands].should == [:incubus, :foo_fighters]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should allow blocks to given to options" do
|
43
|
-
@matcher.builder {|i| i + 10 }
|
44
|
-
@matcher.options[:builder].call(10).should == 20
|
45
|
-
|
46
|
-
@matcher.builder proc{|i| i + 20 }
|
47
|
-
@matcher.options[:builder].call(10).should == 30
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "as optionals=" do
|
52
|
-
it "should allow optionals to be set" do
|
53
|
-
@matcher.first_name = 'José'
|
54
|
-
@matcher.options[:first_name].should == 'José'
|
55
|
-
|
56
|
-
@matcher.last_name = 'Valim'
|
57
|
-
@matcher.options[:last_name].should == 'Valim'
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should allow alias to be set" do
|
61
|
-
@matcher.family_name = 'Valim'
|
62
|
-
@matcher.options[:last_name].should == 'Valim'
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should allow multiple options to be given" do
|
66
|
-
@matcher.bands = [ :incubus, :foo_fighters ]
|
67
|
-
@matcher.options[:bands].should == [ :incubus, :foo_fighters ]
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should overwrite previous options" do
|
71
|
-
@matcher.bands = [ :incubus ]
|
72
|
-
@matcher.bands = [ :foo_fighters ]
|
73
|
-
@matcher.options[:bands].should == [:foo_fighters]
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should allow blocks to given to options" do
|
77
|
-
@matcher.builder = proc{|i| i + 20 }
|
78
|
-
@matcher.options[:builder].call(10).should == 30
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
describe "with config blocks" do
|
85
|
-
|
86
|
-
def builder(*args, &block)
|
87
|
-
Remarkable::Specs::Matchers::BeAPersonMatcher.new(*args, &block)
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "as optionals" do
|
91
|
-
it "should allow optionals to be set" do
|
92
|
-
matcher = builder do |m|
|
93
|
-
m.first_name 'José'
|
94
|
-
m.last_name 'Valim'
|
95
|
-
end
|
96
|
-
|
97
|
-
matcher.options[:first_name].should == 'José'
|
98
|
-
matcher.options[:last_name].should == 'Valim'
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should allow defaults values" do
|
102
|
-
matcher = builder do |m|
|
103
|
-
m.age
|
104
|
-
end
|
105
|
-
|
106
|
-
matcher.options[:age].should == 18
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should allow alias to be set" do
|
110
|
-
matcher = builder do |m|
|
111
|
-
m.family_name 'Valim'
|
112
|
-
end
|
113
|
-
|
114
|
-
matcher.options[:last_name].should == 'Valim'
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should allow multiple options to be given" do
|
118
|
-
matcher = builder do |m|
|
119
|
-
m.bands(:incubus, :foo_fighters)
|
120
|
-
end
|
121
|
-
|
122
|
-
matcher.options[:bands].should == [:incubus, :foo_fighters]
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should allow multiple options to be appended once at a time" do
|
126
|
-
matcher = builder do |m|
|
127
|
-
m.bands(:incubus)
|
128
|
-
m.bands(:foo_fighters)
|
129
|
-
end
|
130
|
-
|
131
|
-
matcher.options[:bands].should == [:incubus, :foo_fighters]
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should allow blocks to given to options" do
|
135
|
-
matcher = builder do |m|
|
136
|
-
m.builder {|i| i + 10 }
|
137
|
-
end
|
138
|
-
|
139
|
-
matcher.options[:builder].call(10).should == 20
|
140
|
-
|
141
|
-
matcher = builder do |m|
|
142
|
-
m.builder proc {|i| i + 20 }
|
143
|
-
end
|
144
|
-
|
145
|
-
matcher.options[:builder].call(10).should == 30
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "as optionals=" do
|
150
|
-
it "should allow optionals to be set" do
|
151
|
-
matcher = builder do |m|
|
152
|
-
m.first_name = 'José'
|
153
|
-
m.last_name = 'Valim'
|
154
|
-
end
|
155
|
-
|
156
|
-
matcher.options[:first_name].should == 'José'
|
157
|
-
matcher.options[:last_name].should == 'Valim'
|
158
|
-
end
|
159
|
-
|
160
|
-
it "should allow alias to be set" do
|
161
|
-
matcher = builder do |m|
|
162
|
-
m.family_name = 'Valim'
|
163
|
-
end
|
164
|
-
|
165
|
-
matcher.options[:last_name].should == 'Valim'
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should allow multiple options to be given" do
|
169
|
-
matcher = builder do |m|
|
170
|
-
m.bands = [ :incubus, :foo_fighters ]
|
171
|
-
end
|
172
|
-
|
173
|
-
matcher.options[:bands].should == [ :incubus, :foo_fighters ]
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should overwrite previous options" do
|
177
|
-
matcher = builder do |m|
|
178
|
-
m.bands = [ :incubus ]
|
179
|
-
m.bands = [ :foo_fighters ]
|
180
|
-
end
|
181
|
-
|
182
|
-
matcher.options[:bands].should == [ :foo_fighters ]
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should allow blocks to given to options" do
|
186
|
-
matcher = builder do |m|
|
187
|
-
m.builder = proc {|i| i + 20 }
|
188
|
-
end
|
189
|
-
|
190
|
-
matcher.options[:builder].call(10).should == 30
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
end
|
195
|
-
|
196
|
-
describe "description" do
|
197
|
-
it "should provide a description with optionals" do
|
198
|
-
matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
|
199
|
-
matcher.description.should == 'contain 1 not checking for blank'
|
200
|
-
|
201
|
-
matcher.allow_blank(10)
|
202
|
-
matcher.description.should == 'contain 1 with blank equal 10'
|
203
|
-
|
204
|
-
matcher.allow_blank(true)
|
205
|
-
matcher.description.should == 'contain 1 with blank equal true'
|
206
|
-
|
207
|
-
matcher.allow_nil(true)
|
208
|
-
matcher.description.should == 'contain 1 allowing nil and with blank equal true'
|
209
|
-
|
210
|
-
matcher.allow_nil(false)
|
211
|
-
matcher.description.should == 'contain 1 not allowing nil and with blank equal true'
|
212
|
-
end
|
213
|
-
|
214
|
-
it "should provide a sentence interpolation option to optionals" do
|
215
|
-
matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
|
216
|
-
matcher.values(1, 2, 3)
|
217
|
-
matcher.description.should == 'contain 1 not checking for blank and values equal to 1, 2, and 3'
|
218
|
-
end
|
219
|
-
|
220
|
-
it "should inspect values in sentence interpolation options" do
|
221
|
-
matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
|
222
|
-
matcher.values(:a, :b, :c)
|
223
|
-
matcher.description.should == 'contain 1 not checking for blank and values equal to :a, :b, and :c'
|
224
|
-
end
|
225
|
-
|
226
|
-
it "should provide a description with optionals through namespace lookup" do
|
227
|
-
matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1)
|
228
|
-
matcher.description.should == 'contain 1'
|
229
|
-
|
230
|
-
matcher.allow_nil(true)
|
231
|
-
matcher.description.should == 'contain 1 allowing nil'
|
232
|
-
|
233
|
-
matcher.allow_nil(false)
|
234
|
-
matcher.description.should == 'contain 1 not allowing nil'
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
+
|
4
|
+
describe Remarkable::DSL::Optionals do
|
5
|
+
|
6
|
+
describe "without config blocks" do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@matcher = Remarkable::Specs::Matchers::BeAPersonMatcher.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "as optionals" do
|
13
|
+
it "should allow optionals to be set" do
|
14
|
+
@matcher.first_name('José')
|
15
|
+
@matcher.options[:first_name].should == 'José'
|
16
|
+
|
17
|
+
@matcher.last_name('Valim')
|
18
|
+
@matcher.options[:last_name].should == 'Valim'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should allow defaults values" do
|
22
|
+
@matcher.age
|
23
|
+
@matcher.options[:age].should == 18
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should allow alias to be set" do
|
27
|
+
@matcher.family_name('Valim')
|
28
|
+
@matcher.options[:last_name].should == 'Valim'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should allow multiple options to be given" do
|
32
|
+
@matcher.bands(:incubus, :foo_fighters)
|
33
|
+
@matcher.options[:bands].should == [:incubus, :foo_fighters]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow multiple options to be appended once at a time" do
|
37
|
+
@matcher.bands(:incubus)
|
38
|
+
@matcher.bands(:foo_fighters)
|
39
|
+
@matcher.options[:bands].should == [:incubus, :foo_fighters]
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should allow blocks to given to options" do
|
43
|
+
@matcher.builder {|i| i + 10 }
|
44
|
+
@matcher.options[:builder].call(10).should == 20
|
45
|
+
|
46
|
+
@matcher.builder proc{|i| i + 20 }
|
47
|
+
@matcher.options[:builder].call(10).should == 30
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "as optionals=" do
|
52
|
+
it "should allow optionals to be set" do
|
53
|
+
@matcher.first_name = 'José'
|
54
|
+
@matcher.options[:first_name].should == 'José'
|
55
|
+
|
56
|
+
@matcher.last_name = 'Valim'
|
57
|
+
@matcher.options[:last_name].should == 'Valim'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should allow alias to be set" do
|
61
|
+
@matcher.family_name = 'Valim'
|
62
|
+
@matcher.options[:last_name].should == 'Valim'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should allow multiple options to be given" do
|
66
|
+
@matcher.bands = [ :incubus, :foo_fighters ]
|
67
|
+
@matcher.options[:bands].should == [ :incubus, :foo_fighters ]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should overwrite previous options" do
|
71
|
+
@matcher.bands = [ :incubus ]
|
72
|
+
@matcher.bands = [ :foo_fighters ]
|
73
|
+
@matcher.options[:bands].should == [:foo_fighters]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should allow blocks to given to options" do
|
77
|
+
@matcher.builder = proc{|i| i + 20 }
|
78
|
+
@matcher.options[:builder].call(10).should == 30
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "with config blocks" do
|
85
|
+
|
86
|
+
def builder(*args, &block)
|
87
|
+
Remarkable::Specs::Matchers::BeAPersonMatcher.new(*args, &block)
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "as optionals" do
|
91
|
+
it "should allow optionals to be set" do
|
92
|
+
matcher = builder do |m|
|
93
|
+
m.first_name 'José'
|
94
|
+
m.last_name 'Valim'
|
95
|
+
end
|
96
|
+
|
97
|
+
matcher.options[:first_name].should == 'José'
|
98
|
+
matcher.options[:last_name].should == 'Valim'
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should allow defaults values" do
|
102
|
+
matcher = builder do |m|
|
103
|
+
m.age
|
104
|
+
end
|
105
|
+
|
106
|
+
matcher.options[:age].should == 18
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should allow alias to be set" do
|
110
|
+
matcher = builder do |m|
|
111
|
+
m.family_name 'Valim'
|
112
|
+
end
|
113
|
+
|
114
|
+
matcher.options[:last_name].should == 'Valim'
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should allow multiple options to be given" do
|
118
|
+
matcher = builder do |m|
|
119
|
+
m.bands(:incubus, :foo_fighters)
|
120
|
+
end
|
121
|
+
|
122
|
+
matcher.options[:bands].should == [:incubus, :foo_fighters]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should allow multiple options to be appended once at a time" do
|
126
|
+
matcher = builder do |m|
|
127
|
+
m.bands(:incubus)
|
128
|
+
m.bands(:foo_fighters)
|
129
|
+
end
|
130
|
+
|
131
|
+
matcher.options[:bands].should == [:incubus, :foo_fighters]
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should allow blocks to given to options" do
|
135
|
+
matcher = builder do |m|
|
136
|
+
m.builder {|i| i + 10 }
|
137
|
+
end
|
138
|
+
|
139
|
+
matcher.options[:builder].call(10).should == 20
|
140
|
+
|
141
|
+
matcher = builder do |m|
|
142
|
+
m.builder proc {|i| i + 20 }
|
143
|
+
end
|
144
|
+
|
145
|
+
matcher.options[:builder].call(10).should == 30
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "as optionals=" do
|
150
|
+
it "should allow optionals to be set" do
|
151
|
+
matcher = builder do |m|
|
152
|
+
m.first_name = 'José'
|
153
|
+
m.last_name = 'Valim'
|
154
|
+
end
|
155
|
+
|
156
|
+
matcher.options[:first_name].should == 'José'
|
157
|
+
matcher.options[:last_name].should == 'Valim'
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should allow alias to be set" do
|
161
|
+
matcher = builder do |m|
|
162
|
+
m.family_name = 'Valim'
|
163
|
+
end
|
164
|
+
|
165
|
+
matcher.options[:last_name].should == 'Valim'
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should allow multiple options to be given" do
|
169
|
+
matcher = builder do |m|
|
170
|
+
m.bands = [ :incubus, :foo_fighters ]
|
171
|
+
end
|
172
|
+
|
173
|
+
matcher.options[:bands].should == [ :incubus, :foo_fighters ]
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should overwrite previous options" do
|
177
|
+
matcher = builder do |m|
|
178
|
+
m.bands = [ :incubus ]
|
179
|
+
m.bands = [ :foo_fighters ]
|
180
|
+
end
|
181
|
+
|
182
|
+
matcher.options[:bands].should == [ :foo_fighters ]
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should allow blocks to given to options" do
|
186
|
+
matcher = builder do |m|
|
187
|
+
m.builder = proc {|i| i + 20 }
|
188
|
+
end
|
189
|
+
|
190
|
+
matcher.options[:builder].call(10).should == 30
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "description" do
|
197
|
+
it "should provide a description with optionals" do
|
198
|
+
matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
|
199
|
+
matcher.description.should == 'contain 1 not checking for blank'
|
200
|
+
|
201
|
+
matcher.allow_blank(10)
|
202
|
+
matcher.description.should == 'contain 1 with blank equal 10'
|
203
|
+
|
204
|
+
matcher.allow_blank(true)
|
205
|
+
matcher.description.should == 'contain 1 with blank equal true'
|
206
|
+
|
207
|
+
matcher.allow_nil(true)
|
208
|
+
matcher.description.should == 'contain 1 allowing nil and with blank equal true'
|
209
|
+
|
210
|
+
matcher.allow_nil(false)
|
211
|
+
matcher.description.should == 'contain 1 not allowing nil and with blank equal true'
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should provide a sentence interpolation option to optionals" do
|
215
|
+
matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
|
216
|
+
matcher.values(1, 2, 3)
|
217
|
+
matcher.description.should == 'contain 1 not checking for blank and values equal to 1, 2, and 3'
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should inspect values in sentence interpolation options" do
|
221
|
+
matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
|
222
|
+
matcher.values(:a, :b, :c)
|
223
|
+
matcher.description.should == 'contain 1 not checking for blank and values equal to :a, :b, and :c'
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should provide a description with optionals through namespace lookup" do
|
227
|
+
matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1)
|
228
|
+
matcher.description.should == 'contain 1'
|
229
|
+
|
230
|
+
matcher.allow_nil(true)
|
231
|
+
matcher.description.should == 'contain 1 allowing nil'
|
232
|
+
|
233
|
+
matcher.allow_nil(false)
|
234
|
+
matcher.description.should == 'contain 1 not allowing nil'
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|