Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reorganize files and fix initialization

  • Loading branch information...
commit d69b3b803367264f27f20d606688ee152924e68a 1 parent 4030072
@ZenCocoon authored
View
2  Appraisals
@@ -1,7 +1,9 @@
appraise "3.0" do
+ gem "i18n", "~> 0.5.0"
gem "activesupport", "~> 3.0"
end
appraise "3.1.0.rc" do
+ gem "i18n", "~> 0.6.0"
gem "activesupport", "~> 3.1.0.rc4"
end
View
21 Gemfile
@@ -1,24 +1,6 @@
source "http://rubygems.org"
-### rspec libs
-%w[rspec rspec-core rspec-expectations rspec-mocks].each do |lib|
- library_path = File.expand_path("../../#{lib}", __FILE__)
- if File.exist?(library_path)
- gem lib, :path => library_path
- else
- gem lib, :git => "git://github.com/rspec/#{lib}.git"
- end
-end
-
-### runtime dependencies
-gem "i18n", ">= 0.5.0"
-gem "activesupport", ">= 3.0"
-
-### dev dependencies
-gem "rake", "~> 0.9"
-gem "cucumber", "1.0.0"
-gem "aruba", "0.4.2"
-gem "nokogiri", "1.4.4"
+gemspec
platforms :jruby do
gem "jruby-openssl"
@@ -29,6 +11,7 @@ group :development do
gem "relish", "0.4.0"
gem 'yard', "~> 0.7.2"
gem "guard-rspec", "0.1.9"
+ gem 'guard-cucumber', "~> 0.5.1"
gem "growl", "1.0.3"
gem "appraisal", :git => "git://github.com/thoughtbot/appraisal.git"
View
8 Guardfile
@@ -2,4 +2,10 @@ guard 'rspec', :version => 2 do
watch(/^spec\/(.*)_spec.rb/)
watch(/^lib\/(.*)\.rb/) { |m| "spec/#{m[1]}_spec.rb" }
watch(/^spec\/spec_helper.rb/) { "spec" }
-end
+end
+
+guard 'cucumber' do
+ watch(%r{^features/.+\.feature$})
+ watch(%r{^features/support/.+$}) { 'features' }
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
+end
View
2  features/.nav
@@ -1,3 +1,3 @@
- Changelog.md
-- Extensions
+- class_methods
- each_attribute_of_subject.feature
View
0  ...ures/extensions/each_attribute_of_subject.feature → ...s/class_methods/each_attribute_of_subject.feature
File renamed without changes
View
7 lib/rspec/subject/extensions.rb
@@ -1,4 +1,5 @@
-require 'rspec/subject/extensions/each'
+require 'rspec/core'
+require 'rspec/subject/extensions/class_methods'
require 'rspec/subject/extensions/version'
module RSpec
@@ -7,4 +8,6 @@ module Subject
module Extensions
end
end
-end
+end
+
+RSpec::Core::ExampleGroup.extend(RSpec::Subject::Extensions::ClassMethods)
View
66 lib/rspec/subject/extensions/class_methods.rb
@@ -0,0 +1,66 @@
+require 'active_support/inflector'
+
+module RSpec
+ module Subject
+ module Extensions
+ module ClassMethods
+ # Creates a nested example group named by +each+ and the submitted +attribute+,
+ # and then generates an example for each attribute using the submitted block.
+ #
+ # @param [Symbol, String] attribute
+ # The singular name of the subject method containing all the attributes.
+ #
+ # @yield
+ # Example to run against each attribute.
+ #
+ # @raise [NoMethodError]
+ # The subject doesn't respond to the pluralized version of the attribute or it doesn't respond to each.
+ #
+ # @example
+ # # This ...
+ # describe Object do
+ # each(:item) { should be_an(Integer) }
+ # end
+ #
+ # # ... generates the same runtime structure as this:
+ # describe Object do
+ # describe "each item"
+ # it "should be an Interger" do
+ # subject.items.each do |item|
+ # item.should be_an(Integer)
+ # end
+ # end
+ # end
+ # end
+ def each(attribute, &block)
+ describe("each #{attribute}") do
+ attribute = attribute.to_s.pluralize
+
+ example do
+ if subject.respond_to?(attribute) && subject.send(attribute).respond_to?(:each)
+ subject.send(attribute).each do |item|
+ self.class.class_eval do
+ define_method(:subject) do
+ @_subject ||= item
+ end
+ end
+
+ instance_eval(&block)
+ end
+ else
+ self.class.class_eval do
+ define_method(:subject) do
+ @_subject ||= super().send(attribute).each
+ end
+ end
+
+ instance_eval(&block)
+ end
+ end
+ end
+ end
+
+ end
+ end
+ end
+end
View
64 lib/rspec/subject/extensions/each.rb
@@ -1,64 +0,0 @@
-require 'active_support/inflector'
-
-module RSpec
- module Subject
- module Extensions
- # Creates a nested example group named by +each+ and the submitted +attribute+,
- # and then generates an example for each attribute using the submitted block.
- #
- # @param [Symbol, String] attribute
- # The singular name of the subject method containing all the attributes.
- #
- # @yield
- # Example to run against each attribute.
- #
- # @raise [NoMethodError]
- # The subject doesn't respond to the pluralized version of the attribute or it doesn't respond to each.
- #
- # @example
- # # This ...
- # describe Object do
- # each(:item) { should be_an(Integer) }
- # end
- #
- # # ... generates the same runtime structure as this:
- # describe Object do
- # describe "each item"
- # it "should be an Interger" do
- # subject.items.each do |item|
- # item.should be_an(Integer)
- # end
- # end
- # end
- # end
- def each(attribute, &block)
- describe("each #{attribute}") do
- attribute = attribute.to_s.pluralize
-
- example do
- if subject.respond_to?(attribute) && subject.send(attribute).respond_to?(:each)
- subject.send(attribute).each do |item|
- self.class.class_eval do
- define_method(:subject) do
- @_subject ||= item
- end
- end
-
- instance_eval(&block)
- end
- else
- self.class.class_eval do
- define_method(:subject) do
- @_subject ||= super().send(attribute).each
- end
- end
-
- instance_eval(&block)
- end
- end
- end
- end
-
- end
- end
-end
View
8 rspec-subject-extensions.gemspec
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.email = "public@zencocoon.com"
s.homepage = "http://github.com/ZenCocoon/rspec-subject-extensions"
s.summary = "rspec-subject-extensions-#{RSpec::Subject::Extensions::Version::STRING}"
- s.description = "rspec subject extensions (each)"
+ s.description = "rspec-subject-extensions let's you use short-hands to generate nested examples groups"
s.files = `git ls-files -- lib/*`.split("\n")
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
@@ -18,6 +18,12 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.require_path = "lib"
+ s.add_runtime_dependency 'rspec', '~> 2.6.0'
s.add_runtime_dependency 'i18n', '>= 0.5.0'
s.add_runtime_dependency 'activesupport', '>= 3.0'
+
+ s.add_development_dependency "rake", "~> 0.9"
+ s.add_development_dependency "cucumber", "1.0.0"
+ s.add_development_dependency "aruba", "0.4.2"
+ s.add_development_dependency "nokogiri", "1.4.4"
end
View
8 spec/rspec/subject/extensions/each_spec.rb → spec/rspec/subject/extensions/class_methods_spec.rb
@@ -1,6 +1,12 @@
require 'spec_helper'
-module RSpec::Subject::Extensions
+module RSpec::Subject::Extensions::ClassMethods
+ describe "initialization" do
+ it "should extend RSpec::Core::ExampleGroup with RSpec::Subject::Extensions::ClassMethods" do
+ RSpec::Core::ExampleGroup.respond_to?('each').should be_true
+ end
+ end
+
describe "#each" do
context "with an Object having #items returning an Array of Integers" do
subject do
View
1  spec/spec_helper.rb
@@ -1,4 +1,3 @@
-require 'rspec/core'
require 'rspec/subject/extensions'
RSpec::configure do |config|
Please sign in to comment.
Something went wrong with that request. Please try again.