Permalink
Browse files

move top-level modules to RSpec::Rails namespace

  • Loading branch information...
1 parent b39e5fd commit a6a35a67c4d1ac2e5274dedae9f92c8049abc9b3 @dchelimsky dchelimsky committed May 28, 2010
@@ -1,33 +1,35 @@
require 'action_controller'
require 'webrat'
-module ControllerExampleGroupBehaviour
- extend ActiveSupport::Concern
+module RSpec::Rails
+ module ControllerExampleGroup
+ extend ActiveSupport::Concern
- include RSpec::Rails::SetupAndTeardownAdapter
- include RSpec::Rails::TestUnitAssertionAdapter
- include ActionController::TestCase::Behavior
- include RSpec::Rails::ViewRendering
- include Webrat::Matchers
- include Webrat::Methods
- include RSpec::Matchers
+ include RSpec::Rails::SetupAndTeardownAdapter
+ include RSpec::Rails::TestUnitAssertionAdapter
+ include ActionController::TestCase::Behavior
+ include RSpec::Rails::ViewRendering
+ include Webrat::Matchers
+ include Webrat::Methods
+ include RSpec::Matchers
- attr_reader :controller
+ attr_reader :controller
- module ClassMethods
- def controller_class
- describes
+ module ClassMethods
+ def controller_class
+ describes
+ end
end
- end
- included do
- before do
- @routes = ::Rails.application.routes
- ActionController::Base.allow_forgery_protection = false
+ included do
+ before do
+ @routes = ::Rails.application.routes
+ ActionController::Base.allow_forgery_protection = false
+ end
end
- end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/controllers\// }
+ RSpec.configure do |c|
+ c.include self, :example_group => { :file_path => /\bspec\/controllers\// }
+ end
end
end
@@ -1,43 +1,44 @@
require 'webrat'
require 'rspec/rails/view_assigns'
-module HelperExampleGroupBehaviour
- extend ActiveSupport::Concern
-
- include RSpec::Rails::SetupAndTeardownAdapter
- include RSpec::Rails::TestUnitAssertionAdapter
- include ActionView::TestCase::Behavior
- include RSpec::Rails::ViewAssigns
- include Webrat::Matchers
-
- module ClassMethods
- def determine_default_helper_class(ignore)
- describes
+module RSpec::Rails
+ module HelperExampleGroup
+ extend ActiveSupport::Concern
+
+ include RSpec::Rails::SetupAndTeardownAdapter
+ include RSpec::Rails::TestUnitAssertionAdapter
+ include ActionView::TestCase::Behavior
+ include RSpec::Rails::ViewAssigns
+ include Webrat::Matchers
+
+ module ClassMethods
+ def determine_default_helper_class(ignore)
+ describes
+ end
end
- end
- module InstanceMethods
- # Returns an instance of ActionView::Base instrumented with this helper and
- # any of the built-in rails helpers.
- def helper
- _view
- end
+ module InstanceMethods
+ # Returns an instance of ActionView::Base instrumented with this helper and
+ # any of the built-in rails helpers.
+ def helper
+ _view
+ end
- private
+ private
- def _controller_path
- running_example.example_group.describes.to_s.sub(/Helper/,'').underscore
+ def _controller_path
+ running_example.example_group.describes.to_s.sub(/Helper/,'').underscore
+ end
end
- end
- included do
- before do
- controller.controller_path = _controller_path
+ included do
+ before do
+ controller.controller_path = _controller_path
+ end
end
- end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/helpers\// }
+ RSpec.configure do |c|
+ c.include self, :example_group => { :file_path => /\bspec\/helpers\// }
+ end
end
end
-
@@ -1,27 +1,29 @@
require 'webrat'
-module MailerExampleGroupBehaviour
- extend ActiveSupport::Concern
+module RSpec::Rails
+ module MailerExampleGroup
+ extend ActiveSupport::Concern
- include Webrat::Matchers
- include RSpec::Matchers
+ include Webrat::Matchers
+ include RSpec::Matchers
- def read_fixture(action)
- IO.readlines(File.join(Rails.root, 'spec', 'fixtures', self.described_class.name.underscore, action))
- end
+ def read_fixture(action)
+ IO.readlines(File.join(Rails.root, 'spec', 'fixtures', self.described_class.name.underscore, action))
+ end
- included do
- before do
- ActionMailer::Base.delivery_method = :test
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.deliveries.clear
- @expected = Mail.new
- @expected.content_type ["text", "plain", { "charset" => "utf-8" }]
- @expected.mime_version = '1.0'
+ included do
+ before do
+ ActionMailer::Base.delivery_method = :test
+ ActionMailer::Base.perform_deliveries = true
+ ActionMailer::Base.deliveries.clear
+ @expected = Mail.new
+ @expected.content_type ["text", "plain", { "charset" => "utf-8" }]
+ @expected.mime_version = '1.0'
+ end
end
- end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/mailers\// }
+ RSpec.configure do |c|
+ c.include self, :example_group => { :file_path => /\bspec\/mailers\// }
+ end
end
end
@@ -1,35 +1,37 @@
require 'action_dispatch'
require 'webrat'
-module RequestExampleGroupBehaviour
- extend ActiveSupport::Concern
+module RSpec::Rails
+ module RequestExampleGroup
+ extend ActiveSupport::Concern
- include ActionDispatch::Integration::Runner
- include RSpec::Rails::TestUnitAssertionAdapter
- include ActionDispatch::Assertions
- include Webrat::Matchers
- include Webrat::Methods
- include RSpec::Matchers
+ include ActionDispatch::Integration::Runner
+ include RSpec::Rails::TestUnitAssertionAdapter
+ include ActionDispatch::Assertions
+ include Webrat::Matchers
+ include Webrat::Methods
+ include RSpec::Matchers
- included do
- before do
- @router = ::Rails.application.routes
+ included do
+ before do
+ @router = ::Rails.application.routes
+ end
+ end
+
+ def app
+ ::Rails.application
end
- end
-
- def app
- ::Rails.application
- end
- def last_response
- response
- end
+ def last_response
+ response
+ end
- Webrat.configure do |config|
- config.mode = :rack
- end
+ Webrat.configure do |config|
+ config.mode = :rack
+ end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/requests\// }
+ RSpec.configure do |c|
+ c.include self, :example_group => { :file_path => /\bspec\/requests\// }
+ end
end
end
@@ -1,62 +1,64 @@
require 'webrat'
require 'rspec/rails/view_assigns'
-module ViewExampleGroupBehaviour
- extend ActiveSupport::Concern
-
- include RSpec::Rails::SetupAndTeardownAdapter
- include RSpec::Rails::TestUnitAssertionAdapter
- include ActionView::TestCase::Behavior
- include RSpec::Rails::ViewAssigns
- include Webrat::Matchers
-
- module InstanceMethods
- def response
- RSpec.deprecate("response", "rendered")
- rendered
- end
+module RSpec::Rails
+ module ViewExampleGroup
+ extend ActiveSupport::Concern
- # :callseq:
- # render
- # render(:template => "widgets/new.html.erb")
- # render({:partial => "widgets/widget.html.erb"}, {... locals ...})
- # render({:partial => "widgets/widget.html.erb"}, {... locals ...}) do ... end
- #
- # Delegates to ActionView::Base#render, so see documentation on that for more
- # info.
- #
- # The only addition is that you can call render with no arguments, and RSpec
- # will pass the top level description to render:
- #
- # describe "widgets/new.html.erb" do
- # it "shows all the widgets" do
- # render # => view.render(:file => "widgets/new.html.erb")
- # ...
- # end
- # end
- def render(options={}, local_assigns={}, &block)
- options = {:template => _default_file_to_render} if Hash === options and options.empty?
- super(options, local_assigns, &block)
- end
+ include RSpec::Rails::SetupAndTeardownAdapter
+ include RSpec::Rails::TestUnitAssertionAdapter
+ include ActionView::TestCase::Behavior
+ include RSpec::Rails::ViewAssigns
+ include Webrat::Matchers
- private
+ module InstanceMethods
+ def response
+ RSpec.deprecate("response", "rendered")
+ rendered
+ end
- def _default_file_to_render
- running_example.example_group.top_level_description
- end
+ # :callseq:
+ # render
+ # render(:template => "widgets/new.html.erb")
+ # render({:partial => "widgets/widget.html.erb"}, {... locals ...})
+ # render({:partial => "widgets/widget.html.erb"}, {... locals ...}) do ... end
+ #
+ # Delegates to ActionView::Base#render, so see documentation on that for more
+ # info.
+ #
+ # The only addition is that you can call render with no arguments, and RSpec
+ # will pass the top level description to render:
+ #
+ # describe "widgets/new.html.erb" do
+ # it "shows all the widgets" do
+ # render # => view.render(:file => "widgets/new.html.erb")
+ # ...
+ # end
+ # end
+ def render(options={}, local_assigns={}, &block)
+ options = {:template => _default_file_to_render} if Hash === options and options.empty?
+ super(options, local_assigns, &block)
+ end
+
+ private
- def _controller_path
- _default_file_to_render.split("/")[0..-2].join("/")
+ def _default_file_to_render
+ running_example.example_group.top_level_description
+ end
+
+ def _controller_path
+ _default_file_to_render.split("/")[0..-2].join("/")
+ end
end
- end
- included do
- before do
- controller.controller_path = _controller_path
+ included do
+ before do
+ controller.controller_path = _controller_path
+ end
end
- end
- RSpec.configure do |c|
- c.include self, :example_group => { :file_path => /\bspec\/views\// }
+ RSpec.configure do |c|
+ c.include self, :example_group => { :file_path => /\bspec\/views\// }
+ end
end
end
@@ -1,11 +1,13 @@
require "spec_helper"
-describe ControllerExampleGroupBehaviour 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(ControllerExampleGroupBehaviour)
+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
end
end
Oops, something went wrong.

0 comments on commit a6a35a6

Please sign in to comment.