remarkable 3.0.8 → 3.0.9

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.
@@ -33,7 +33,7 @@ describe Remarkable::DSL::Assertions do
33
33
 
34
34
  it 'should accept blocks as argument' do
35
35
  should_not single_contain(4)
36
- should single_contain(4){ |array| array << 4 }
36
+ should single_contain(4){ self << 4 }
37
37
  end
38
38
 
39
39
  it 'should provide an interface for default_options hook' do
@@ -1,53 +1,236 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe Remarkable::DSL::Optionals do
4
- before(:each) do
5
- @matcher = Remarkable::Specs::Matchers::BeAPersonMatcher.new
6
- end
3
+ describe Remarkable::DSL::Optionals do
4
+
5
+ describe "without config blocks" do
6
+
7
+ before(:each) do
8
+ @matcher = Remarkable::Specs::Matchers::BeAPersonMatcher.new
9
+ end
10
+
11
+ describe "as optionals" do
12
+ it "should allow optionals to be set" do
13
+ @matcher.first_name('José')
14
+ @matcher.options[:first_name].should == 'José'
7
15
 
8
- it "should create optional methods on the fly" do
9
- @matcher.first_name('José')
10
- @matcher.instance_variable_get('@options')[:first_name].should == 'José'
16
+ @matcher.last_name('Valim')
17
+ @matcher.options[:last_name].should == 'Valim'
18
+ end
19
+
20
+ it "should allow defaults values" do
21
+ @matcher.age
22
+ @matcher.options[:age].should == 18
23
+ end
11
24
 
12
- @matcher.last_name('Valim')
13
- @matcher.instance_variable_get('@options')[:last_name].should == 'Valim'
14
- end
25
+ it "should allow alias to be set" do
26
+ @matcher.family_name('Valim')
27
+ @matcher.options[:last_name].should == 'Valim'
28
+ end
29
+
30
+ it "should allow multiple options to be given" do
31
+ @matcher.bands(:incubus, :foo_fighters)
32
+ @matcher.options[:bands].should == [:incubus, :foo_fighters]
33
+ end
34
+
35
+ it "should allow multiple options to be appended once at a time" do
36
+ @matcher.bands(:incubus)
37
+ @matcher.bands(:foo_fighters)
38
+ @matcher.options[:bands].should == [:incubus, :foo_fighters]
39
+ end
40
+
41
+ it "should allow blocks to given to options" do
42
+ @matcher.builder {|i| i + 10 }
43
+ @matcher.options[:builder].call(10).should == 20
44
+
45
+ @matcher.builder proc{|i| i + 20 }
46
+ @matcher.options[:builder].call(10).should == 30
47
+ end
48
+ end
49
+
50
+ describe "as optionals=" do
51
+ it "should allow optionals to be set" do
52
+ @matcher.first_name = 'José'
53
+ @matcher.options[:first_name].should == 'José'
15
54
 
16
- it "should allow defaults values" do
17
- @matcher.age
18
- @matcher.instance_variable_get('@options')[:age].should == 18
19
- end
55
+ @matcher.last_name = 'Valim'
56
+ @matcher.options[:last_name].should == 'Valim'
57
+ end
58
+
59
+ it "should allow alias to be set" do
60
+ @matcher.family_name = 'Valim'
61
+ @matcher.options[:last_name].should == 'Valim'
62
+ end
63
+
64
+ it "should allow multiple options to be given" do
65
+ @matcher.bands = [ :incubus, :foo_fighters ]
66
+ @matcher.options[:bands].should == [ :incubus, :foo_fighters ]
67
+ end
68
+
69
+ it "should overwrite previous options" do
70
+ @matcher.bands = [ :incubus ]
71
+ @matcher.bands = [ :foo_fighters ]
72
+ @matcher.options[:bands].should == [:foo_fighters]
73
+ end
74
+
75
+ it "should allow blocks to given to options" do
76
+ @matcher.builder = proc{|i| i + 20 }
77
+ @matcher.options[:builder].call(10).should == 30
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ describe "with config blocks" do
84
+
85
+ def builder(*args, &block)
86
+ Remarkable::Specs::Matchers::BeAPersonMatcher.new(*args, &block)
87
+ end
88
+
89
+ describe "as optionals" do
90
+ it "should allow optionals to be set" do
91
+ matcher = builder do |m|
92
+ m.first_name 'José'
93
+ m.last_name 'Valim'
94
+ end
95
+
96
+ matcher.options[:first_name].should == 'José'
97
+ matcher.options[:last_name].should == 'Valim'
98
+ end
99
+
100
+ it "should allow defaults values" do
101
+ matcher = builder do |m|
102
+ m.age
103
+ end
20
104
 
21
- it "should allow alias to be set" do
22
- @matcher.family_name('Valim')
23
- @matcher.instance_variable_get('@options')[:last_name].should == 'Valim'
24
- end
105
+ matcher.options[:age].should == 18
106
+ end
25
107
 
26
- it 'should provide a description with optionals' do
27
- @matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
28
- @matcher.description.should == 'contain 1 not checking for blank'
108
+ it "should allow alias to be set" do
109
+ matcher = builder do |m|
110
+ m.family_name 'Valim'
111
+ end
29
112
 
30
- @matcher.allow_blank(10)
31
- @matcher.description.should == 'contain 1 with blank equal 10'
113
+ matcher.options[:last_name].should == 'Valim'
114
+ end
115
+
116
+ it "should allow multiple options to be given" do
117
+ matcher = builder do |m|
118
+ m.bands(:incubus, :foo_fighters)
119
+ end
120
+
121
+ matcher.options[:bands].should == [:incubus, :foo_fighters]
122
+ end
123
+
124
+ it "should allow multiple options to be appended once at a time" do
125
+ matcher = builder do |m|
126
+ m.bands(:incubus)
127
+ m.bands(:foo_fighters)
128
+ end
129
+
130
+ matcher.options[:bands].should == [:incubus, :foo_fighters]
131
+ end
132
+
133
+ it "should allow blocks to given to options" do
134
+ matcher = builder do |m|
135
+ m.builder {|i| i + 10 }
136
+ end
137
+
138
+ matcher.options[:builder].call(10).should == 20
139
+
140
+ matcher = builder do |m|
141
+ m.builder proc {|i| i + 20 }
142
+ end
143
+
144
+ matcher.options[:builder].call(10).should == 30
145
+ end
146
+ end
147
+
148
+ describe "as optionals=" do
149
+ it "should allow optionals to be set" do
150
+ matcher = builder do |m|
151
+ m.first_name = 'José'
152
+ m.last_name = 'Valim'
153
+ end
154
+
155
+ matcher.options[:first_name].should == 'José'
156
+ matcher.options[:last_name].should == 'Valim'
157
+ end
158
+
159
+ it "should allow alias to be set" do
160
+ matcher = builder do |m|
161
+ m.family_name = 'Valim'
162
+ end
163
+
164
+ matcher.options[:last_name].should == 'Valim'
165
+ end
166
+
167
+ it "should allow multiple options to be given" do
168
+ matcher = builder do |m|
169
+ m.bands = [ :incubus, :foo_fighters ]
170
+ end
171
+
172
+ matcher.options[:bands].should == [ :incubus, :foo_fighters ]
173
+ end
174
+
175
+ it "should overwrite previous options" do
176
+ matcher = builder do |m|
177
+ m.bands = [ :incubus ]
178
+ m.bands = [ :foo_fighters ]
179
+ end
180
+
181
+ matcher.options[:bands].should == [ :foo_fighters ]
182
+ end
183
+
184
+ it "should allow blocks to given to options" do
185
+ matcher = builder do |m|
186
+ m.builder = proc {|i| i + 20 }
187
+ end
188
+
189
+ matcher.options[:builder].call(10).should == 30
190
+ end
191
+ end
192
+
193
+ end
194
+
195
+ describe "description" do
196
+ it "should provide a description with optionals" do
197
+ matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
198
+ matcher.description.should == 'contain 1 not checking for blank'
32
199
 
33
- @matcher.allow_blank(true)
34
- @matcher.description.should == 'contain 1 with blank equal true'
200
+ matcher.allow_blank(10)
201
+ matcher.description.should == 'contain 1 with blank equal 10'
35
202
 
36
- @matcher.allow_nil(true)
37
- @matcher.description.should == 'contain 1 allowing nil and with blank equal true'
203
+ matcher.allow_blank(true)
204
+ matcher.description.should == 'contain 1 with blank equal true'
38
205
 
39
- @matcher.allow_nil(false)
40
- @matcher.description.should == 'contain 1 not allowing nil and with blank equal true'
41
- end
206
+ matcher.allow_nil(true)
207
+ matcher.description.should == 'contain 1 allowing nil and with blank equal true'
208
+
209
+ matcher.allow_nil(false)
210
+ matcher.description.should == 'contain 1 not allowing nil and with blank equal true'
211
+ end
212
+
213
+ it "should provide a sentence interpolation option to optionals" do
214
+ matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
215
+ matcher.values(1, 2, 3)
216
+ matcher.description.should == 'contain 1 not checking for blank and values equal to 1, 2, and 3'
217
+ end
218
+
219
+ it "should inspect values in sentence interpolation options" do
220
+ matcher = Remarkable::Specs::Matchers::SingleContainMatcher.new(1)
221
+ matcher.values(:a, :b, :c)
222
+ matcher.description.should == 'contain 1 not checking for blank and values equal to :a, :b, and :c'
223
+ end
42
224
 
43
- it 'should provide a description with optionals through namespace lookup' do
44
- @matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1)
45
- @matcher.description.should == 'contain 1'
225
+ it "should provide a description with optionals through namespace lookup" do
226
+ matcher = Remarkable::Specs::Matchers::CollectionContainMatcher.new(1)
227
+ matcher.description.should == 'contain 1'
46
228
 
47
- @matcher.allow_nil(true)
48
- @matcher.description.should == 'contain 1 allowing nil'
229
+ matcher.allow_nil(true)
230
+ matcher.description.should == 'contain 1 allowing nil'
49
231
 
50
- @matcher.allow_nil(false)
51
- @matcher.description.should == 'contain 1 not allowing nil'
232
+ matcher.allow_nil(false)
233
+ matcher.description.should == 'contain 1 not allowing nil'
234
+ end
52
235
  end
53
236
  end
@@ -15,7 +15,9 @@ en:
15
15
  negative: "not allowing nil"
16
16
  allow_blank:
17
17
  positive: "with blank equal {{inspect}}"
18
- not_given: "not checking for blank"
18
+ not_given: "not checking for blank"
19
+ values:
20
+ positive: "values equal to {{sentence}}"
19
21
  collection_contain:
20
22
  description: "contain {{values}}"
21
23
  expectations:
@@ -21,6 +21,6 @@ describe Remarkable::Macros do
21
21
  subject { [1, 2, 3] }
22
22
 
23
23
  should_not_single_contain(4)
24
- should_single_contain(4){ |array| array << 4 }
24
+ should_single_contain(4){ self << 4 }
25
25
  end
26
26
  end
@@ -6,7 +6,11 @@ module Remarkable
6
6
 
7
7
  optional :first_name
8
8
  optional :age, :default => 18
9
- optional :last_name, :alias => :family_name
9
+ optional :last_name, :alias => :family_name
10
+ optional :bands, :splat => true
11
+ optional :builder, :block => true
12
+
13
+ attr_reader :options
10
14
 
11
15
  def description
12
16
  "be a person"
@@ -24,8 +24,8 @@ module Remarkable
24
24
  end
25
25
  end
26
26
 
27
- def collection_contain(*args)
28
- CollectionContainMatcher.new(*args).spec(self)
27
+ def collection_contain(*args, &block)
28
+ CollectionContainMatcher.new(*args, &block).spec(self)
29
29
  end
30
30
  end
31
31
  end
@@ -23,8 +23,8 @@ module Remarkable
23
23
  end
24
24
  end
25
25
 
26
- def contain(*args)
27
- ContainMatcher.new(*args).spec(self)
26
+ def contain(*args, &block)
27
+ ContainMatcher.new(*args, &block).spec(self)
28
28
  end
29
29
  end
30
30
  end
@@ -7,13 +7,14 @@ module Remarkable
7
7
  assertions :is_array?, :included?
8
8
 
9
9
  optional :allow_nil
10
- optional :allow_blank
10
+ optional :allow_blank
11
+ optional :values, :splat => true
11
12
 
12
13
  after_initialize :set_after_initialize
13
14
 
14
15
  before_assert do
15
- @before_assert = true
16
- @iterator.call(@subject) if @iterator
16
+ @before_assert = true
17
+ @subject.instance_eval(&@iterator) if @iterator
17
18
  end
18
19
 
19
20
  protected
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remarkable
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.8
4
+ version: 3.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Brando
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-04-24 00:00:00 +02:00
13
+ date: 2009-04-25 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -42,7 +42,6 @@ files:
42
42
  - lib/remarkable/pending.rb
43
43
  - lib/remarkable/dsl/assertions.rb
44
44
  - lib/remarkable/dsl/optionals.rb
45
- - lib/remarkable/dsl/matches.rb
46
45
  - lib/remarkable/dsl/callbacks.rb
47
46
  - lib/remarkable/rspec.rb
48
47
  - lib/remarkable/base.rb
@@ -1,139 +0,0 @@
1
- module Remarkable
2
- module DSL
3
- module Matches
4
-
5
- # For each instance under the collection declared in <tt>arguments</tt>,
6
- # this method will call each method declared in <tt>collection_assertions</tt>.
7
- #
8
- # As an example, let's assume you have the following matcher:
9
- #
10
- # arguments :collection => :attributes
11
- # assertions :allow_nil?, :allow_blank?
12
- #
13
- # For each attribute in @attributes, we will set the instance variable
14
- # @attribute and then call allow_nil? and allow_blank?. Assertions should
15
- # return true if it pass or false if it fails. When it fails, it will use
16
- # I18n API to find the proper failure message:
17
- #
18
- # expectations:
19
- # allow_nil?: allowed the value to be nil
20
- # allow_blank?: allowed the value to be blank
21
- #
22
- # Or you can set the message in the instance variable @expectation in the
23
- # assertion method if you don't want to rely on I18n API.
24
- #
25
- # This method also call the methods declared in single_assertions. Which
26
- # work the same way as assertions, except it doesn't loop for each value in
27
- # the collection.
28
- #
29
- # It also provides a before_assert callback that you might want to use it
30
- # to manipulate the subject before the assertions start.
31
- #
32
- def matches?(subject)
33
- @subject = subject
34
-
35
- run_before_assert_callbacks
36
-
37
- send_methods_and_generate_message(self.class.matcher_single_assertions) &&
38
- assert_matcher_for(instance_variable_get("@#{self.class.matcher_arguments[:collection]}") || []) do |value|
39
- instance_variable_set("@#{self.class.matcher_arguments[:as]}", value)
40
- send_methods_and_generate_message(self.class.matcher_collection_assertions)
41
- end
42
- end
43
-
44
- protected
45
-
46
- # Overwrite to provide default options.
47
- #
48
- def default_options
49
- {}
50
- end
51
-
52
- # Overwrites default_i18n_options to provide arguments and optionals
53
- # to interpolation options.
54
- #
55
- # If you still need to provide more other interpolation options, you can
56
- # do that in two ways:
57
- #
58
- # 1. Overwrite interpolation_options:
59
- #
60
- # def interpolation_options
61
- # { :real_value => real_value }
62
- # end
63
- #
64
- # 2. Return a hash from your assertion method:
65
- #
66
- # def my_assertion
67
- # return true if real_value == expected_value
68
- # return false, :real_value => real_value
69
- # end
70
- #
71
- # In both cases, :real_value will be available as interpolation option.
72
- #
73
- def default_i18n_options #:nodoc:
74
- i18n_options = {}
75
-
76
- @options.each do |key, value|
77
- i18n_options[key] = value.inspect
78
- end if @options
79
-
80
- # Also add arguments as interpolation options.
81
- self.class.matcher_arguments[:names].each do |name|
82
- i18n_options[name] = instance_variable_get("@#{name}").inspect
83
- end
84
-
85
- # Add collection interpolation options.
86
- i18n_options.update(collection_interpolation)
87
-
88
- # Add default options (highest priority). They should not be overwritten.
89
- i18n_options.update(super)
90
- end
91
-
92
- # Method responsible to add collection as interpolation.
93
- #
94
- def collection_interpolation #:nodoc:
95
- options = {}
96
-
97
- if collection_name = self.class.matcher_arguments[:collection]
98
- collection_name = collection_name.to_sym
99
- collection = instance_variable_get("@#{collection_name}")
100
- options[collection_name] = array_to_sentence(collection) if collection
101
-
102
- object_name = self.class.matcher_arguments[:as].to_sym
103
- object = instance_variable_get("@#{object_name}")
104
- options[object_name] = object if object
105
- end
106
-
107
- options
108
- end
109
-
110
- # Send the assertion methods given and create a expectation message
111
- # if any of those methods returns false.
112
- #
113
- # Since most assertion methods ends with an question mark and it's not
114
- # readable in yml files, we remove question and exclation marks at the
115
- # end of the method name before translating it. So if you have a method
116
- # called is_valid? on I18n yml file we will check for a key :is_valid.
117
- #
118
- def send_methods_and_generate_message(methods) #:nodoc:
119
- methods.each do |method|
120
- bool, hash = send(method)
121
-
122
- unless bool
123
- parent_scope = matcher_i18n_scope.split('.')
124
- matcher_name = parent_scope.pop
125
- lookup = :"expectations.#{method.to_s.gsub(/(\?|\!)$/, '')}"
126
-
127
- hash = { :scope => parent_scope, :default => lookup }.merge(hash || {})
128
- @expectation ||= Remarkable.t "#{matcher_name}.#{lookup}", default_i18n_options.merge(hash)
129
-
130
- return false
131
- end
132
- end
133
-
134
- return true
135
- end
136
-
137
- end
138
- end
139
- end