Skip to content
Browse files

Ensure that modules for different kind of specs get included in specs in

files in the appropriate directories _even on Windows_.

Closes #99.
  • Loading branch information...
1 parent f30f213 commit 9910fedf9f7c6ca4bb5768523ed8ecf938b8667f @dchelimsky dchelimsky committed Jun 25, 2010
View
1 lib/rspec/rails.rb
@@ -6,5 +6,6 @@
require 'rspec/rails/matchers'
require 'rspec/rails/fixture_support'
require 'rspec/rails/mocks'
+require 'rspec/rails/module_inclusion'
require 'rspec/rails/example'
View
5 lib/rspec/rails/example/controller_example_group.rb
@@ -75,6 +75,7 @@ module RSpec::Rails
#
module ControllerExampleGroup
extend ActiveSupport::Concern
+ extend RSpec::Rails::ModuleInclusion
include RSpec::Rails::SetupAndTeardownAdapter
include RSpec::Rails::TestUnitAssertionAdapter
@@ -104,8 +105,6 @@ module InstanceMethods
end
end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/controllers\// }
- end
+ RSpec.configure &include_self_when_dir_matches('spec','controllers')
end
end
View
7 lib/rspec/rails/example/helper_example_group.rb
@@ -28,7 +28,8 @@ module RSpec::Rails
# end
#
module HelperExampleGroup
- extend ActiveSupport::Concern
+ extend ActiveSupport::Concern
+ extend RSpec::Rails::ModuleInclusion
include RSpec::Rails::SetupAndTeardownAdapter
include RSpec::Rails::TestUnitAssertionAdapter
@@ -62,8 +63,6 @@ def _controller_path
end
end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/helpers\// }
- end
+ RSpec.configure &include_self_when_dir_matches('spec','helpers')
end
end
View
6 lib/rspec/rails/example/mailer_example_group.rb
@@ -4,9 +4,9 @@
module RSpec::Rails
module MailerExampleGroup
extend ActiveSupport::Concern
+ extend RSpec::Rails::ModuleInclusion
include ActionMailer::TestCase::Behavior
-
include Webrat::Matchers
include RSpec::Matchers
@@ -16,8 +16,6 @@ def mailer_class
end
end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/mailers\// }
- end
+ RSpec.configure &include_self_when_dir_matches('spec','mailers')
end
end
View
5 lib/rspec/rails/example/request_example_group.rb
@@ -16,6 +16,7 @@ module RSpec::Rails
# => delegates to assert_redirected_to(destination)
module RequestExampleGroup
extend ActiveSupport::Concern
+ extend RSpec::Rails::ModuleInclusion
include ActionDispatch::Integration::Runner
include RSpec::Rails::TestUnitAssertionAdapter
@@ -47,8 +48,6 @@ def last_response
end
end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/requests\// }
- end
+ RSpec.configure &include_self_when_dir_matches('spec','requests')
end
end
View
5 lib/rspec/rails/example/routing_example_group.rb
@@ -3,6 +3,7 @@
module RSpec::Rails
module RoutingExampleGroup
extend ActiveSupport::Concern
+ extend RSpec::Rails::ModuleInclusion
include RSpec::Rails::TestUnitAssertionAdapter
include ActionDispatch::Assertions::RoutingAssertions
@@ -18,8 +19,6 @@ module InstanceMethods
end
end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/routing\// }
- end
+ RSpec.configure &include_self_when_dir_matches('spec','routing')
end
end
View
7 lib/rspec/rails/example/view_example_group.rb
@@ -20,7 +20,8 @@ module RSpec::Rails
# end
# end
module ViewExampleGroup
- extend ActiveSupport::Concern
+ extend ActiveSupport::Concern
+ extend RSpec::Rails::ModuleInclusion
include RSpec::Rails::SetupAndTeardownAdapter
include RSpec::Rails::TestUnitAssertionAdapter
@@ -108,8 +109,6 @@ def _controller_path
end
end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/views\// }
- end
+ RSpec.configure &include_self_when_dir_matches('spec','views')
end
end
View
11 lib/rspec/rails/module_inclusion.rb
@@ -0,0 +1,11 @@
+module RSpec::Rails
+ module ModuleInclusion
+ def include_self_when_dir_matches(*path_parts)
+ lambda do |c|
+ c.include self, :example_group => {
+ :file_path => Regexp.compile(path_parts.join('[\\\/]'))
+ }
+ end
+ end
+ end
+end
View
3 rspec-rails.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["David Chelimsky", "Chad Humphries"]
- s.date = %q{2010-06-24}
+ s.date = %q{2010-06-25}
s.description = %q{RSpec-2 for Rails-3}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
s.extra_rdoc_files = [
@@ -87,6 +87,7 @@ Gem::Specification.new do |s|
"lib/rspec/rails/matchers/render_template.rb",
"lib/rspec/rails/matchers/routing_matchers.rb",
"lib/rspec/rails/mocks.rb",
+ "lib/rspec/rails/module_inclusion.rb",
"lib/rspec/rails/monkey.rb",
"lib/rspec/rails/monkey/action_mailer/test_case.rb",
"lib/rspec/rails/version.rb",
View
9 spec/rspec/rails/example/controller_example_group_spec.rb
@@ -2,13 +2,8 @@
module RSpec::Rails
describe ControllerExampleGroup do
- it "is included in specs in ./spec/controllers" do
- stub_metadata(
- :example_group => {:file_path => "./spec/controllers/whatever_spec.rb:15"}
- )
- group = RSpec::Core::ExampleGroup.describe
- group.included_modules.should include(ControllerExampleGroup)
- end
+ it { should be_included_in_files_in('./spec/controllers/') }
+ it { should be_included_in_files_in('.\\spec\\controllers\\') }
it "includes routing matchers" do
group = RSpec::Core::ExampleGroup.describe do
View
10 spec/rspec/rails/example/helper_example_group_spec.rb
@@ -3,14 +3,10 @@
module RSpec::Rails
describe HelperExampleGroup::InstanceMethods do
module ::FoosHelper; end
+ subject { HelperExampleGroup }
- it "is included in specs in ./spec/views" do
- stub_metadata(
- :example_group => {:file_path => "./spec/helpers/whatever_spec.rb:15"}
- )
- group = RSpec::Core::ExampleGroup.describe
- group.included_modules.should include(HelperExampleGroup)
- end
+ it { should be_included_in_files_in('./spec/helpers/') }
+ it { should be_included_in_files_in('.\\spec\\helpers\\') }
it "provides a controller_path based on the helper module's name" do
helper_spec = Object.new.extend HelperExampleGroup::InstanceMethods
View
9 spec/rspec/rails/example/mailer_example_group_spec.rb
@@ -2,12 +2,7 @@
module RSpec::Rails
describe MailerExampleGroup do
- it "is included in specs in ./spec/mailers" do
- stub_metadata(
- :example_group => {:file_path => "./spec/mailers/whatever_spec.rb:15"}
- )
- group = RSpec::Core::ExampleGroup.describe
- group.included_modules.should include(MailerExampleGroup)
- end
+ it { should be_included_in_files_in('./spec/mailers/') }
+ it { should be_included_in_files_in('.\\spec\\mailers\\') }
end
end
View
9 spec/rspec/rails/example/request_example_group_spec.rb
@@ -2,12 +2,7 @@
module RSpec::Rails
describe RequestExampleGroup do
- it "is included in specs in ./spec/requests" do
- stub_metadata(
- :example_group => {:file_path => "./spec/requests/whatever_spec.rb:15"}
- )
- group = RSpec::Core::ExampleGroup.describe
- group.included_modules.should include(RequestExampleGroup)
- end
+ it { should be_included_in_files_in('./spec/requests/') }
+ it { should be_included_in_files_in('.\\spec\\requests\\') }
end
end
View
9 spec/rspec/rails/example/routing_example_group_spec.rb
@@ -2,12 +2,7 @@
module RSpec::Rails
describe RoutingExampleGroup do
- it "is included in specs in ./spec/routing" do
- stub_metadata(
- :example_group => {:file_path => "./spec/routing/whatever_spec.rb:15"}
- )
- group = RSpec::Core::ExampleGroup.describe
- group.included_modules.should include(RoutingExampleGroup)
- end
+ it { should be_included_in_files_in('./spec/routing/') }
+ it { should be_included_in_files_in('.\\spec\\routing\\') }
end
end
View
9 spec/rspec/rails/example/view_example_group_spec.rb
@@ -2,13 +2,8 @@
module RSpec::Rails
describe ViewExampleGroup do
- it "is included in specs in ./spec/views" do
- stub_metadata(
- :example_group => {:file_path => "./spec/views/whatever_spec.rb:15"}
- )
- group = RSpec::Core::ExampleGroup.describe
- group.included_modules.should include(ViewExampleGroup)
- end
+ it { should be_included_in_files_in('./spec/views/') }
+ it { should be_included_in_files_in('.\\spec\\views\\') }
describe "#render" do
let(:view_spec) do
View
15 spec/spec_helper.rb
@@ -17,7 +17,22 @@ def self.run_all(reporter=nil)
end
end
+module MatchesForRSpecRailsSpecs
+ extend RSpec::Matchers::DSL
+
+ matcher :be_included_in_files_in do |path|
+ match do |mod|
+ stub_metadata(
+ :example_group => {:file_path => "#{path}whatever_spec.rb:15"}
+ )
+ group = RSpec::Core::ExampleGroup.describe
+ group.included_modules.include?(mod)
+ end
+ end
+end
+
RSpec.configure do |c|
+ c.include MatchesForRSpecRailsSpecs
c.color_enabled = !in_editor?
c.before(:each) do
@real_world = RSpec.world

0 comments on commit 9910fed

Please sign in to comment.
Something went wrong with that request. Please try again.