rspec-requestable-examples 0.1.5 → 0.1.6

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.
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2012 Zach Dennis, Mutually Human Software
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
@@ -0,0 +1,360 @@
1
+ Feature: Requestable examples
2
+
3
+ Requestable examples are RSpec's shared examples with the addition that you can
4
+ define examples which you can explicitly request later when you include the
5
+ requestable example group. Because of this they are a super-set of shared examples.
6
+
7
+ Requestable example groups can be defined using the following mechanism:
8
+
9
+ requestable_examples "description goes here" do ; ... ; end
10
+
11
+ Using this mechanism you have four new methods available to you when writing examples:
12
+
13
+ requestable_it "name"
14
+ requestable_example "name"
15
+
16
+ requestable_describe "name"
17
+ requestable_context "name"
18
+
19
+ You can mix it/describe/context with the above mechanisms, but when you use the
20
+ traditional mechanisms those examples will ALWAYS be included. Now, onto using
21
+ requestable example groups.
22
+
23
+ Requestable example groups can be included in another group using the same mechanisms
24
+ that you use when using shared example groups, e.g.:
25
+
26
+ include_examples "name" # include the examples in the current context
27
+ it_behaves_like "name" # include the examples in a nested context
28
+ it_should_behave_like "name" # include the examples in a nested context
29
+
30
+ If you do not pass in any additional options (see below) then all examples are
31
+ run. However, if you pass the :examples option with the names of the examples to
32
+ run then the requested examples will only run ones that you've specified!
33
+
34
+ include_examples "name", :examples => ["example #1"]
35
+ it_behaves_like "name", :examples => ["example #1"] # include the examples in a nested context
36
+ it_should_behave_like "name", :examples => ["example #1"]
37
+
38
+ For more information on how to use these see the corresponding scenarios.
39
+
40
+ Background:
41
+ Given a file named "spec_helper.rb" with:
42
+ """
43
+ require "../../lib/rspec-requestable-examples"
44
+ RSpec.configure do |config|
45
+ config.extend RSpec::RequestableExamples
46
+ end
47
+ """
48
+
49
+ Scenario: Ommitting all examples includes them all
50
+ Given a file named "collection_spec.rb" with:
51
+ """
52
+ require "./spec_helper"
53
+ require "set"
54
+
55
+ requestable_examples "a collection with items" do |options|
56
+ let(:collection) { described_class.new([7, 2, 4]) }
57
+
58
+ requestable_example "is not empty" do
59
+ collection.should_not be_empty
60
+ end
61
+
62
+ requestable_it "has more than 0 items" do
63
+ collection.should_not be_empty
64
+ end
65
+ end
66
+
67
+ describe Array do
68
+ it_behaves_like "a collection with items"
69
+ end
70
+
71
+ describe Set do
72
+ it_behaves_like "a collection with items"
73
+ end
74
+ """
75
+ When I run `rspec collection_spec.rb --format documentation`
76
+ Then the examples should all pass
77
+ And the output should contain:
78
+ """
79
+ Array
80
+ behaves like a collection with items
81
+ is not empty
82
+ has more than 0 items
83
+
84
+ Set
85
+ behaves like a collection with items
86
+ is not empty
87
+ has more than 0 items
88
+ """
89
+
90
+ Scenario: Including specific examples
91
+ Given a file named "collection_spec.rb" with:
92
+ """
93
+ require "./spec_helper"
94
+ require "set"
95
+
96
+ requestable_examples "a collection with items" do |options|
97
+ let(:collection) { described_class.new([7, 2, 4]) }
98
+
99
+ requestable_example "is not empty" do
100
+ collection.should_not be_empty
101
+ end
102
+
103
+ requestable_it "has more than 0 items" do
104
+ collection.should_not be_empty
105
+ end
106
+ end
107
+
108
+ describe Array do
109
+ it_behaves_like "a collection with items", :examples => [
110
+ "is not empty"
111
+ ]
112
+ end
113
+
114
+ describe Set do
115
+ it_behaves_like "a collection with items", :examples => [
116
+ "has more than 0 items"
117
+ ]
118
+ end
119
+ """
120
+ When I run `rspec collection_spec.rb --format documentation`
121
+ Then the examples should all pass
122
+ And the output should contain:
123
+ """
124
+ Array
125
+ behaves like a collection with items
126
+ is not empty
127
+
128
+ Set
129
+ behaves like a collection with items
130
+ has more than 0 items
131
+ """
132
+
133
+ Scenario: Traditional "it" and "describe" examples are always run even when not specified
134
+ Given a file named "collection_spec.rb" with:
135
+ """
136
+ require "./spec_helper"
137
+ require "set"
138
+
139
+ requestable_examples "a collection with items" do |options|
140
+ let(:collection) { described_class.new([7, 2, 4]) }
141
+
142
+ it "always runs traditional examples" do
143
+ true.should be_true
144
+ end
145
+
146
+ describe "always runs traditional describes" do
147
+ it "is true" do
148
+ true.should be_true
149
+ end
150
+ end
151
+
152
+ requestable_example "is not empty" do
153
+ collection.should_not be_empty
154
+ end
155
+
156
+ requestable_it "has more than 0 items" do
157
+ collection.should_not be_empty
158
+ end
159
+ end
160
+
161
+ describe Array do
162
+ it_behaves_like "a collection with items", :examples => []
163
+ end
164
+
165
+ describe Set do
166
+ it_behaves_like "a collection with items", :examples => ["is not empty"]
167
+ end
168
+ """
169
+ When I run `rspec collection_spec.rb --format documentation`
170
+ Then the examples should all pass
171
+ And the output should contain:
172
+ """
173
+ Array
174
+ behaves like a collection with items
175
+ always runs traditional examples
176
+ always runs traditional describes
177
+ is true
178
+
179
+ Set
180
+ behaves like a collection with items
181
+ always runs traditional examples
182
+ is not empty
183
+ always runs traditional describes
184
+ is true
185
+ """
186
+
187
+
188
+ Scenario: Including aliased examples
189
+ Given a file named "collection_spec.rb" with:
190
+ """
191
+ require "./spec_helper"
192
+ require "set"
193
+
194
+ requestable_examples "a collection with items" do |options|
195
+ let(:collection) { described_class.new([7, 2, 4]) }
196
+
197
+ requestable_example "is not empty", :as => "not empty" do
198
+ collection.should_not be_empty
199
+ end
200
+
201
+ requestable_example "has more than 0 items", :as => "contains at least 1 or more items" do
202
+ collection.should_not be_empty
203
+ end
204
+ end
205
+
206
+ describe Array do
207
+ it_behaves_like "a collection with items", :examples => [
208
+ "not empty"
209
+ ]
210
+ end
211
+
212
+ describe Set do
213
+ it_behaves_like "a collection with items", :examples => [
214
+ "contains at least 1 or more items"
215
+ ]
216
+ end
217
+ """
218
+ When I run `rspec collection_spec.rb --format documentation`
219
+ Then the examples should all pass
220
+ And the output should contain:
221
+ """
222
+ Array
223
+ behaves like a collection with items
224
+ is not empty
225
+
226
+ Set
227
+ behaves like a collection with items
228
+ has more than 0 items
229
+ """
230
+
231
+ Scenario Outline: Including specific <type> blocks
232
+ Given a file named "collection_spec.rb" with:
233
+ """
234
+ require "./spec_helper"
235
+ require "set"
236
+
237
+ requestable_examples "a collection with items" do |options|
238
+ let(:collection) { described_class.new([7, 2, 4]) }
239
+
240
+ requestable_<type> "collection rules" do
241
+ it "is not empty" do
242
+ collection.should_not be_empty
243
+ end
244
+ end
245
+ end
246
+
247
+ describe Array do
248
+ it_behaves_like "a collection with items", :examples => [
249
+ "collection rules"
250
+ ]
251
+ end
252
+
253
+ describe Set do
254
+ it_behaves_like "a collection with items", :examples => [
255
+ "collection rules"
256
+ ]
257
+ end
258
+ """
259
+ When I run `rspec collection_spec.rb --format documentation`
260
+ Then the examples should all pass
261
+ And the output should contain:
262
+ """
263
+ Array
264
+ behaves like a collection with items
265
+ collection rules
266
+ is not empty
267
+
268
+ Set
269
+ behaves like a collection with items
270
+ collection rules
271
+ is not empty
272
+ """
273
+
274
+ Examples:
275
+ | type |
276
+ | describe |
277
+ | context |
278
+
279
+ Scenario Outline: Including aliased <type> blocks
280
+ Given a file named "collection_spec.rb" with:
281
+ """
282
+ require "./spec_helper"
283
+ require "set"
284
+
285
+ requestable_examples "a collection with items" do |options|
286
+ let(:collection) { described_class.new([7, 2, 4]) }
287
+
288
+ requestable_<type> "collection rules", :as => "aliased collection rules" do
289
+ it "is not empty" do
290
+ collection.should_not be_empty
291
+ end
292
+ end
293
+ end
294
+
295
+ describe Array do
296
+ it_behaves_like "a collection with items", :examples => [
297
+ "aliased collection rules"
298
+ ]
299
+ end
300
+
301
+ describe Set do
302
+ it_behaves_like "a collection with items", :examples => [
303
+ "aliased collection rules"
304
+ ]
305
+ end
306
+ """
307
+ When I run `rspec collection_spec.rb --format documentation`
308
+ Then the examples should all pass
309
+ And the output should contain:
310
+ """
311
+ Array
312
+ behaves like a collection with items
313
+ collection rules
314
+ is not empty
315
+
316
+ Set
317
+ behaves like a collection with items
318
+ collection rules
319
+ is not empty
320
+ """
321
+
322
+ Examples:
323
+ | type |
324
+ | describe |
325
+ | context |
326
+
327
+ Scenario: Requesting examples that don't exist
328
+ Given a file named "collection_spec.rb" with:
329
+ """
330
+ require "./spec_helper"
331
+ require "set"
332
+
333
+ requestable_examples "a collection with items" do |options|
334
+ end
335
+
336
+ describe Array do
337
+ it_behaves_like "a collection with items", :examples => [
338
+ "collection rules"
339
+ ]
340
+ end
341
+
342
+ describe Set do
343
+ it_behaves_like "a collection with items", :examples => [
344
+ "collection rules"
345
+ ]
346
+ end
347
+ """
348
+ When I run `rspec collection_spec.rb --format documentation`
349
+ Then the output should contain "2 examples, 0 failures, 2 pending"
350
+ And the output should contain:
351
+ """
352
+ Array
353
+ behaves like a collection with items
354
+ collection rules (PENDING: This example was requested but isn't defined, typo?)
355
+
356
+ Set
357
+ behaves like a collection with items
358
+ collection rules (PENDING: This example was requested but isn't defined, typo?)
359
+ """
360
+
@@ -0,0 +1,4 @@
1
+ Then /^the example(?:s)? should(?: all)? pass$/ do
2
+ step %q{the output should contain "0 failures"}
3
+ step %q{the exit status should be 0}
4
+ end
@@ -0,0 +1,12 @@
1
+ require 'aruba/cucumber'
2
+
3
+ Before do
4
+ if RUBY_PLATFORM =~ /java/
5
+ # ideas taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
6
+ set_env('JRUBY_OPTS', '-X-C') # disable JIT since these processes are so short lived
7
+ set_env('JAVA_OPTS', '-d32') # force jRuby to use client JVM for faster startup times
8
+ @aruba_timeout_seconds = 60
9
+ else
10
+ @aruba_timeout_seconds = 5
11
+ end
12
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rspec/requestable-examples"
@@ -1,17 +1,41 @@
1
1
  module RSpec
2
2
  module RequestableExamples
3
+ include RSpec::Core::SharedExampleGroup
4
+
3
5
  class RequestedExamples < Array
4
6
  def initialize(options)
5
7
  options ||= {}
8
+ @do_not_run_any_examples = true if options[:examples] == []
6
9
  replace options[:examples] || []
7
10
  end
8
11
 
9
12
  def run?(example)
13
+ return false if @do_not_run_any_examples
10
14
  return true if empty? || include?(example)
11
15
  false
12
16
  end
13
17
  end
14
-
18
+
19
+ def requestable_examples(*args, &block)
20
+ if [String, Symbol, Module].any? {|cls| cls === args.first }
21
+ object = args.shift
22
+ ensure_shared_example_group_name_not_taken(object)
23
+ RSpec.world.shared_example_groups[object] = lambda do |options={}|
24
+ request_examples options
25
+ instance_eval(&block)
26
+ verify_requested_examples!
27
+ end
28
+ end
29
+
30
+ unless args.empty?
31
+ mod = Module.new
32
+ (class << mod; self; end).send(:define_method, :extended) do |host|
33
+ host.class_eval(&block)
34
+ end
35
+ RSpec.configuration.extend(mod, *args)
36
+ end
37
+ end
38
+
15
39
  def examples_that_can_be_requested
16
40
  @examples_that_can_be_requested ||= []
17
41
  end
@@ -31,10 +55,6 @@ module RSpec
31
55
  end
32
56
  alias_method :requestable_it, :requestable_example
33
57
 
34
- def requestable_examples
35
- @requestable_examples ||= []
36
- end
37
-
38
58
  def requestable_describe(description, options={}, &blk)
39
59
  label = options[:as] || description
40
60
  examples_that_can_be_requested << label
@@ -52,4 +72,6 @@ module RSpec
52
72
  end
53
73
  end
54
74
 
55
- end
75
+ end
76
+
77
+ include RSpec::RequestableExamples
@@ -0,0 +1,7 @@
1
+ module RSpec # :nodoc:
2
+ module RequestableExamples # :nodoc:
3
+ module Version # :nodoc:
4
+ STRING = '0.1.6'
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rspec-requestable-examples
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.5
5
+ version: 0.1.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Zach Dennis
@@ -10,10 +10,64 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-12 00:00:00 Z
14
- dependencies: []
15
-
16
- description: See home page
13
+ date: 2012-01-24 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.2
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: cucumber
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 1.1.0
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: aruba
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.4.11
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: fakefs
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - "="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.4.0
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: syntax
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - "="
66
+ - !ruby/object:Gem::Version
67
+ version: 1.0.0
68
+ type: :development
69
+ version_requirements: *id005
70
+ description: Let's you include specific examples from shared example sets.
17
71
  email: zach.dennis@gmail.com
18
72
  executables: []
19
73
 
@@ -22,13 +76,20 @@ extensions: []
22
76
  extra_rdoc_files: []
23
77
 
24
78
  files:
79
+ - lib/rspec-requestable-examples.rb
25
80
  - lib/rspec/requestable-examples.rb
26
- homepage: http://www.continuousthinking.com
27
- licenses: []
28
-
81
+ - lib/rspec/requestable-examples/version.rb
82
+ - README.markdown
83
+ - License.txt
84
+ - features/requestable_examples.feature
85
+ - features/step_definitions/additional_cli_steps.rb
86
+ - features/support/env.rb
87
+ homepage: http://github.com/mhs/rspec-requestable-examples
88
+ licenses:
89
+ - MIT
29
90
  post_install_message:
30
- rdoc_options: []
31
-
91
+ rdoc_options:
92
+ - --charset=UTF-8
32
93
  require_paths:
33
94
  - lib
34
95
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -46,10 +107,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
107
  requirements: []
47
108
 
48
109
  rubyforge_project:
49
- rubygems_version: 1.8.13
110
+ rubygems_version: 1.8.15
50
111
  signing_key:
51
112
  specification_version: 3
52
- summary: rspec-requestable-examples let's you include specific examples from shared example sets
53
- test_files: []
54
-
113
+ summary: rspec-requestable-examples-0.1.6
114
+ test_files:
115
+ - features/requestable_examples.feature
116
+ - features/step_definitions/additional_cli_steps.rb
117
+ - features/support/env.rb
55
118
  has_rdoc: