rspec-subject-extensions 0.1.0 → 0.2.0

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.
data/README.md CHANGED
@@ -1,16 +1,14 @@
1
- # RSpec Subject Extensions
1
+ # RSpec Subject Extensions [![build status](http://travis-ci.org/ZenCocoon/rspec-subject-extensions.png)](http://travis-ci.org/ZenCocoon/rspec-subject-extensions)
2
2
 
3
3
  rspec-subject-extensions adds `each` short-hand to generate a nested example group with
4
4
  a single example that specifies the expected value of each attribute of the subject.
5
5
 
6
- [![build status](http://travis-ci.org/ZenCocoon/rspec-subject-extensions.png)](http://travis-ci.org/ZenCocoon/rspec-subject-extensions)
7
-
8
6
  ## Documentation
9
7
 
10
8
  The [Cucumber features](http://relishapp.com/ZenCocoon/rspec-subject-extensions)
11
9
  are the most comprehensive and up-to-date docs for end-users.
12
10
 
13
- The [RDoc](http://rubydoc.info/gems/rspec-subject-extensions/0.1.0/frames) provides
11
+ The [RDoc](http://rubydoc.info/gems/rspec-subject-extensions/0.2.0/frames) provides
14
12
  additional information for contributors and/or extenders.
15
13
 
16
14
  All of the documentation is open source and a work in progress. If you find it
@@ -22,6 +20,12 @@ tracker](https://github.com/ZenCocoon/rspec-subject-extensions/issues).
22
20
 
23
21
  gem install rspec-subject-extensions
24
22
 
23
+ ## Requirements
24
+
25
+ rspec ~> 2.6.0
26
+ i18n >= 0.5.0
27
+ activesupport >= 3.0
28
+
25
29
  ## Usage
26
30
 
27
31
  ### Each
@@ -53,3 +57,7 @@ The `attribute` can be a `Symbol` or a `String`.
53
57
  * [http://github.com/rspec/rspec-core](http://github.com/rspec/rspec-core)
54
58
  * [http://github.com/rspec/rspec-expectations](http://github.com/rspec/rspec-expectations)
55
59
  * [http://github.com/rspec/rspec-mocks](http://github.com/rspec/rspec-mocks)
60
+
61
+ ## License
62
+
63
+ MIT License. Copyright 2011 Sébastien Grosjean, sponsored by [BookingSync, Vacation Rental's Booking Calendar Software](http://www.bookingsync.com)
@@ -12,7 +12,7 @@ Feature: each attribute of subject
12
12
  Scenario: specify value of each attribute
13
13
  Given a file named "example_spec.rb" with:
14
14
  """
15
- require 'rspec/subject/extensions'
15
+ require 'rspec-subject-extensions'
16
16
 
17
17
  class Movie
18
18
  def ratings
@@ -1 +1,9 @@
1
- require 'rspec/subject/extensions'
1
+ require 'rspec/core'
2
+ require 'rspec-subject-extensions/class_methods'
3
+ require 'rspec-subject-extensions/version'
4
+
5
+ # RSpecSubjectExtensions let's you use short-hands to generate nested examples groups
6
+ module RSpecSubjectExtensions
7
+ end
8
+
9
+ RSpec::Core::ExampleGroup.extend(RSpecSubjectExtensions::ClassMethods)
@@ -0,0 +1,62 @@
1
+ require 'active_support/inflector'
2
+
3
+ module RSpecSubjectExtensions
4
+ module ClassMethods
5
+ # Creates a nested example group named by +each+ and the submitted +attribute+,
6
+ # and then generates an example for each attribute using the submitted block.
7
+ #
8
+ # @param [Symbol, String] attribute
9
+ # The singular name of the subject method containing all the attributes.
10
+ #
11
+ # @yield
12
+ # Example to run against each attribute.
13
+ #
14
+ # @raise [NoMethodError]
15
+ # The subject doesn't respond to the pluralized version of the attribute or it doesn't respond to each.
16
+ #
17
+ # @example
18
+ # # This ...
19
+ # describe Object do
20
+ # each(:item) { should be_an(Integer) }
21
+ # end
22
+ #
23
+ # # ... generates the same runtime structure as this:
24
+ # describe Object do
25
+ # describe "each item"
26
+ # it "should be an Interger" do
27
+ # subject.items.each do |item|
28
+ # item.should be_an(Integer)
29
+ # end
30
+ # end
31
+ # end
32
+ # end
33
+ def each(attribute, &block)
34
+ describe("each #{attribute}") do
35
+ attribute = attribute.to_s.pluralize
36
+
37
+ example do
38
+ if subject.respond_to?(attribute) && subject.send(attribute).respond_to?(:each)
39
+ subject.send(attribute).each do |item|
40
+ self.class.class_eval do
41
+ define_method(:subject) do
42
+ @_subject ||= item
43
+ end
44
+ end
45
+
46
+ instance_eval(&block)
47
+ end
48
+ else
49
+ self.class.class_eval do
50
+ define_method(:subject) do
51
+ @_subject ||= super().send(attribute).each
52
+ end
53
+ end
54
+
55
+ instance_eval(&block)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,6 @@
1
+ module RSpecSubjectExtensions
2
+ # @private
3
+ module Version
4
+ STRING = '0.2.0'
5
+ end
6
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- module RSpec::Subject::Extensions::ClassMethods
3
+ module RSpecSubjectExtensions::ClassMethods
4
4
  describe "initialization" do
5
- it "should extend RSpec::Core::ExampleGroup with RSpec::Subject::Extensions::ClassMethods" do
5
+ it "should extend RSpec::Core::ExampleGroup with RSpecSubjectExtensions::ClassMethods" do
6
6
  RSpec::Core::ExampleGroup.respond_to?('each').should be_true
7
7
  end
8
8
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'rspec/subject/extensions'
1
+ require 'rspec-subject-extensions'
2
2
 
3
3
  RSpec::configure do |config|
4
4
  config.color_enabled = true
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-subject-extensions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "S\xC3\xA9bastien Grosjean"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-02 00:00:00 +03:00
18
+ date: 2011-07-08 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -216,12 +216,12 @@ dependencies:
216
216
  requirements:
217
217
  - - ~>
218
218
  - !ruby/object:Gem::Version
219
- hash: 31
219
+ hash: 29
220
220
  segments:
221
221
  - 0
222
222
  - 3
223
- - 6
224
- version: 0.3.6
223
+ - 7
224
+ version: 0.3.7
225
225
  type: :development
226
226
  version_requirements: *id013
227
227
  description: rspec-subject-extensions let's you use short-hands to generate nested examples groups
@@ -234,14 +234,13 @@ extra_rdoc_files:
234
234
  - README.md
235
235
  files:
236
236
  - lib/rspec-subject-extensions.rb
237
- - lib/rspec/subject/extensions.rb
238
- - lib/rspec/subject/extensions/class_methods.rb
239
- - lib/rspec/subject/extensions/version.rb
237
+ - lib/rspec-subject-extensions/class_methods.rb
238
+ - lib/rspec-subject-extensions/version.rb
240
239
  - README.md
241
240
  - features/README.md
242
241
  - features/class_methods/each_attribute_of_subject.feature
243
242
  - features/support/env.rb
244
- - spec/rspec/subject/extensions/class_methods_spec.rb
243
+ - spec/rspec-subject-extensions/class_methods_spec.rb
245
244
  - spec/spec_helper.rb
246
245
  has_rdoc: true
247
246
  homepage: http://github.com/ZenCocoon/rspec-subject-extensions
@@ -276,10 +275,10 @@ rubyforge_project:
276
275
  rubygems_version: 1.6.2
277
276
  signing_key:
278
277
  specification_version: 3
279
- summary: rspec-subject-extensions-0.1.0
278
+ summary: rspec-subject-extensions-0.2.0
280
279
  test_files:
281
280
  - features/README.md
282
281
  - features/class_methods/each_attribute_of_subject.feature
283
282
  - features/support/env.rb
284
- - spec/rspec/subject/extensions/class_methods_spec.rb
283
+ - spec/rspec-subject-extensions/class_methods_spec.rb
285
284
  - spec/spec_helper.rb
@@ -1,13 +0,0 @@
1
- require 'rspec/core'
2
- require 'rspec/subject/extensions/class_methods'
3
- require 'rspec/subject/extensions/version'
4
-
5
- module RSpec
6
- module Subject
7
- # RSpec::Subject::Extensions let's you use short-hands to generate nested examples groups
8
- module Extensions
9
- end
10
- end
11
- end
12
-
13
- RSpec::Core::ExampleGroup.extend(RSpec::Subject::Extensions::ClassMethods)
@@ -1,66 +0,0 @@
1
- require 'active_support/inflector'
2
-
3
- module RSpec
4
- module Subject
5
- module Extensions
6
- module ClassMethods
7
- # Creates a nested example group named by +each+ and the submitted +attribute+,
8
- # and then generates an example for each attribute using the submitted block.
9
- #
10
- # @param [Symbol, String] attribute
11
- # The singular name of the subject method containing all the attributes.
12
- #
13
- # @yield
14
- # Example to run against each attribute.
15
- #
16
- # @raise [NoMethodError]
17
- # The subject doesn't respond to the pluralized version of the attribute or it doesn't respond to each.
18
- #
19
- # @example
20
- # # This ...
21
- # describe Object do
22
- # each(:item) { should be_an(Integer) }
23
- # end
24
- #
25
- # # ... generates the same runtime structure as this:
26
- # describe Object do
27
- # describe "each item"
28
- # it "should be an Interger" do
29
- # subject.items.each do |item|
30
- # item.should be_an(Integer)
31
- # end
32
- # end
33
- # end
34
- # end
35
- def each(attribute, &block)
36
- describe("each #{attribute}") do
37
- attribute = attribute.to_s.pluralize
38
-
39
- example do
40
- if subject.respond_to?(attribute) && subject.send(attribute).respond_to?(:each)
41
- subject.send(attribute).each do |item|
42
- self.class.class_eval do
43
- define_method(:subject) do
44
- @_subject ||= item
45
- end
46
- end
47
-
48
- instance_eval(&block)
49
- end
50
- else
51
- self.class.class_eval do
52
- define_method(:subject) do
53
- @_subject ||= super().send(attribute).each
54
- end
55
- end
56
-
57
- instance_eval(&block)
58
- end
59
- end
60
- end
61
- end
62
-
63
- end
64
- end
65
- end
66
- end
@@ -1,10 +0,0 @@
1
- module RSpec
2
- module Subject
3
- module Extensions
4
- # @private
5
- module Version
6
- STRING = '0.1.0'
7
- end
8
- end
9
- end
10
- end