Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Include rails-specific example group extensions based on :type key.

- e.g. describe "something", :type => :controller do
- reworked internal module inclusion functionality
- include request spec extensions in spec/integration for ease of
  upgrade from rspec-rails-1.x
- Closes #256.
commit fc5cdbb603f0e66f9f3d19a0a60a775e124fb218 1 parent c3c258a
@dchelimsky dchelimsky authored
View
1  lib/rspec/rails.rb
@@ -15,4 +15,3 @@
require 'rspec/rails/browser_simulators'
require 'rspec/rails/example'
-
View
30 lib/rspec/rails/example.rb
@@ -5,4 +5,32 @@
require 'rspec/rails/example/view_example_group'
require 'rspec/rails/example/mailer_example_group'
require 'rspec/rails/example/routing_example_group'
-require 'rspec/rails/example/model_example_group'
+require 'rspec/rails/example/model_example_group'
+
+RSpec::configure do |c|
+ def c.escaped_path(*parts)
+ Regexp.compile(parts.join('[\\\/]'))
+ end
+
+ c.include RSpec::Rails::ControllerExampleGroup, :type => :controller, :example_group => {
+ :file_path => c.escaped_path(%w[spec controllers])
+ }
+ c.include RSpec::Rails::HelperExampleGroup, :type => :helper, :example_group => {
+ :file_path => c.escaped_path(%w[spec helpers])
+ }
+ c.include RSpec::Rails::MailerExampleGroup, :type => :mailer, :example_group => {
+ :file_path => c.escaped_path(%w[spec mailers])
+ }
+ c.include RSpec::Rails::ModelExampleGroup, :type => :model, :example_group => {
+ :file_path => c.escaped_path(%w[spec models])
+ }
+ c.include RSpec::Rails::RequestExampleGroup, :type => :request, :example_group => {
+ :file_path => c.escaped_path(%w[spec (requests|integration)])
+ }
+ c.include RSpec::Rails::RoutingExampleGroup, :type => :routing, :example_group => {
+ :file_path => c.escaped_path(%w[spec routing])
+ }
+ c.include RSpec::Rails::ViewExampleGroup, :type => :view, :example_group => {
+ :file_path => c.escaped_path(%w[spec views])
+ }
+end
View
6 lib/rspec/rails/example/controller_example_group.rb
@@ -72,11 +72,9 @@ module RSpec::Rails
#
module ControllerExampleGroup
extend ActiveSupport::Concern
- extend RSpec::Rails::ModuleInclusion
-
- include RSpec::Rails::RailsExampleGroup
include ActionController::TestCase::Behavior
+ include RSpec::Rails::RailsExampleGroup
include RSpec::Rails::ViewRendering
include RSpec::Rails::Matchers::RedirectTo
include RSpec::Rails::Matchers::RenderTemplate
@@ -172,7 +170,5 @@ module InstanceMethods
end
end
end
-
- RSpec.configure &include_self_when_dir_matches('spec','controllers')
end
end
View
6 lib/rspec/rails/example/helper_example_group.rb
@@ -27,11 +27,9 @@ module RSpec::Rails
#
module HelperExampleGroup
extend ActiveSupport::Concern
- extend RSpec::Rails::ModuleInclusion
-
- include RSpec::Rails::RailsExampleGroup
include ActionView::TestCase::Behavior
+ include RSpec::Rails::RailsExampleGroup
include RSpec::Rails::ViewAssigns
include RSpec::Rails::BrowserSimulators
@@ -69,7 +67,5 @@ def _controller_path
controller.controller_path = _controller_path
end
end
-
- RSpec.configure &include_self_when_dir_matches('spec','helpers')
end
end
View
6 lib/rspec/rails/example/mailer_example_group.rb
@@ -2,11 +2,9 @@
module RSpec::Rails
module MailerExampleGroup
extend ActiveSupport::Concern
- extend RSpec::Rails::ModuleInclusion
-
- include RSpec::Rails::RailsExampleGroup
include ActionMailer::TestCase::Behavior
+ include RSpec::Rails::RailsExampleGroup
include RSpec::Rails::BrowserSimulators
webrat do
@@ -29,8 +27,6 @@ def mailer_class
describes
end
end
-
- RSpec.configure &include_self_when_dir_matches('spec','mailers')
end
end
end
View
3  lib/rspec/rails/example/model_example_group.rb
@@ -1,14 +1,11 @@
module RSpec::Rails
module ModelExampleGroup
extend ActiveSupport::Concern
- extend RSpec::Rails::ModuleInclusion
include RSpec::Rails::RailsExampleGroup
included do
metadata[:type] = :model
end
-
- RSpec.configure &include_self_when_dir_matches('spec','models')
end
end
View
6 lib/rspec/rails/example/request_example_group.rb
@@ -13,12 +13,10 @@ module RSpec::Rails
# => delegates to assert_redirected_to(destination)
module RequestExampleGroup
extend ActiveSupport::Concern
- extend RSpec::Rails::ModuleInclusion
-
- include RSpec::Rails::RailsExampleGroup
include ActionDispatch::Integration::Runner
include ActionDispatch::Assertions
+ include RSpec::Rails::RailsExampleGroup
include RSpec::Rails::BrowserSimulators
module InstanceMethods
@@ -62,7 +60,5 @@ def last_response
end
end
end
-
- RSpec.configure &include_self_when_dir_matches('spec','requests')
end
end
View
6 lib/rspec/rails/example/routing_example_group.rb
@@ -3,11 +3,9 @@
module RSpec::Rails
module RoutingExampleGroup
extend ActiveSupport::Concern
- extend RSpec::Rails::ModuleInclusion
-
- include RSpec::Rails::RailsExampleGroup
include ActionDispatch::Assertions::RoutingAssertions
+ include RSpec::Rails::RailsExampleGroup
include RSpec::Rails::Matchers::RoutingMatchers
module InstanceMethods
@@ -27,7 +25,5 @@ def method_missing(m, *args, &block)
@routes = ::Rails.application.routes
end
end
-
- RSpec.configure &include_self_when_dir_matches('spec','routing')
end
end
View
5 lib/rspec/rails/example/view_example_group.rb
@@ -19,10 +19,9 @@ module RSpec::Rails
# end
module ViewExampleGroup
extend ActiveSupport::Concern
- extend RSpec::Rails::ModuleInclusion
- include RSpec::Rails::RailsExampleGroup
include ActionView::TestCase::Behavior
+ include RSpec::Rails::RailsExampleGroup
include RSpec::Rails::ViewAssigns
include RSpec::Rails::Matchers::RenderTemplate
include RSpec::Rails::BrowserSimulators
@@ -154,8 +153,6 @@ def _include_controller_helpers
controller.request.path_parameters["action"] = _inferred_action unless _inferred_action =~ /^_/
end
end
-
- RSpec.configure &include_self_when_dir_matches('spec','views')
end
end
View
2  spec/rspec/rails/example/request_example_group_spec.rb
@@ -3,7 +3,9 @@
module RSpec::Rails
describe RequestExampleGroup do
it { should be_included_in_files_in('./spec/requests/') }
+ it { should be_included_in_files_in('./spec/integration/') }
it { should be_included_in_files_in('.\\spec\\requests\\') }
+ it { should be_included_in_files_in('.\\spec\\integration\\') }
it "adds :type => :request to the metadata" do
group = RSpec::Core::ExampleGroup.describe do
Please sign in to comment.
Something went wrong with that request. Please try again.