Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added configuration to allow for custom application engine.

  • Loading branch information...
commit 83e24bca5d3ca86360a70f76fbe1e592f0ab5e63 1 parent 0677052
Dan Rasband danrasband authored
1  lib/rspec/rails.rb
View
@@ -9,6 +9,7 @@
require 'rspec/rails/view_rendering'
require 'rspec/rails/adapters'
require 'rspec/rails/matchers'
+require 'rspec/rails/engine_support'
require 'rspec/rails/fixture_support'
require 'rspec/rails/mocks'
require 'rspec/rails/module_inclusion'
9 lib/rspec/rails/engine_support.rb
View
@@ -0,0 +1,9 @@
+module RSpec
+ module Rails
+ module EngineSupport
+ RSpec::configure do |config|
+ config.add_setting :application, :default => ::Rails.application
+ end
+ end
+ end
+end
2  lib/rspec/rails/example/controller_example_group.rb
View
@@ -120,7 +120,7 @@ def method_missing(method, *args, &block)
metadata[:type] = :controller
before do
- @routes = ::Rails.application.routes
+ @routes = RSpec.configuration.application.routes
ActionController::Base.allow_forgery_protection = false
end
end
2  lib/rspec/rails/example/mailer_example_group.rb
View
@@ -7,7 +7,7 @@ module MailerExampleGroup
included do
metadata[:type] = :mailer
- include ::Rails.application.routes.url_helpers
+ include RSpec.configuration.application.routes.url_helpers
options = ::Rails.configuration.action_mailer.default_url_options
options.each { |key, value| default_url_options[key] = value } if options
end
4 lib/rspec/rails/example/request_example_group.rb
View
@@ -9,14 +9,14 @@ module RequestExampleGroup
include ActionController::TemplateAssertions
def app
- ::Rails.application
+ RSpec.configuration.application
end
included do
metadata[:type] = :request
before do
- @routes = ::Rails.application.routes
+ @routes = RSpec.configuration.application.routes
end
end
end
2  lib/rspec/rails/example/routing_example_group.rb
View
@@ -12,7 +12,7 @@ module RoutingExampleGroup
metadata[:type] = :routing
before do
- @routes = ::Rails.application.routes
+ @routes = RSpec.configuration.application.routes
end
end
13 spec/rspec/rails/configuration_spec.rb
View
@@ -3,10 +3,12 @@
describe "configuration" do
before do
@orig_render_views = RSpec.configuration.render_views?
+ @orig_application = RSpec.configuration.application
end
after do
RSpec.configuration.render_views = @orig_render_views
+ RSpec.configuration.application = @orig_application
end
describe "#render_views?" do
@@ -23,4 +25,15 @@
RSpec.configuration.render_views?.should be_true
end
end
+
+ describe "#application" do
+ it "is Rails.application by default" do
+ RSpec.configuration.application.should eq(::Rails.application)
+ end
+
+ it "allows for custom application" do
+ RSpec.configuration.application = RSpec::EngineExample
+ RSpec.configuration.application.should eq(RSpec::EngineExample)
+ end
+ end
end
23 spec/rspec/rails/example/controller_example_group_spec.rb
View
@@ -96,5 +96,28 @@ module RSpec::Rails
controller_class.superclass.should eq(ApplicationController)
end
end
+
+ describe "#application" do
+ before do
+ @orig_application = RSpec.configuration.application
+ RSpec.configuration.application = RSpec::EngineExample
+ end
+
+ after do
+ RSpec.configuration.application = @orig_application
+ end
+
+ it "still delegates name routes to underlying controller" do
+ controller = double('controller')
+ controller.stub(:bars_path).and_return('/foos')
+
+ example = group.new
+ example.stub(:controller => controller)
+
+ example.instance_variable_set(:@orig_routes, RSpec.configuration.application.routes)
+
+ example.bars_path.should eq('/foos')
+ end
+ end
end
end
20 spec/rspec/rails/example/mailer_example_group_spec.rb
View
@@ -17,5 +17,25 @@ module ::Rails; end
end
group.metadata[:type].should eq(:mailer)
end
+
+ describe "custom application" do
+ before do
+ @orig_application = RSpec.configuration.application
+ RSpec.configuration.application = RSpec::EngineExample
+ end
+
+ after do
+ RSpec.configuration.application = @orig_application
+ end
+
+ it "should include custom application's url helpers" do
+ group = RSpec::Core::ExampleGroup.describe do
+ include MailerExampleGroup
+ end
+
+ example = group.new
+ example.bars_path.should == '/bars'
+ end
+ end
end
end
21 spec/rspec/rails/example/request_example_group_spec.rb
View
@@ -13,5 +13,26 @@ module RSpec::Rails
end
group.metadata[:type].should eq(:request)
end
+
+ describe "#app" do
+ before do
+ @orig_application = RSpec.configuration.application
+ RSpec.configuration.application = RSpec::EngineExample
+ end
+
+ after do
+ RSpec.configuration.application = @orig_application
+ end
+
+ it "sets app as custom application" do
+ group = RSpec::Core::ExampleGroup.describe do
+ include RequestExampleGroup
+ end
+
+ example = group.new
+
+ example.app.should eq(RSpec::EngineExample)
+ end
+ end
end
end
25 spec/rspec/rails/example/routing_example_group_spec.rb
View
@@ -28,5 +28,30 @@ module RSpec::Rails
example.foo_path.should == "foo"
end
end
+
+ describe "custom application routes" do
+ before do
+ @orig_application = RSpec.configuration.application
+ RSpec.configuration.application = RSpec::EngineExample
+ end
+
+ after do
+ RSpec.configuration.application = @orig_application
+ end
+
+ it "provides routes of custom application" do
+ group = RSpec::Core::ExampleGroup.describe do
+ include RoutingExampleGroup
+ end
+
+ example = group.new
+
+ # Because this relies on before hooks, I have to stub this in.
+ example.stub(:routes => RSpec.configuration.application.routes)
+
+ example.bars_path.should == "/bars"
+ end
+
+ end
end
end
12 spec/support/engine_example.rb
View
@@ -0,0 +1,12 @@
+module RSpec
+ class EngineExample < ::Rails::Engine
+ def self.activate
+ end
+ end
+end
+
+
+RSpec::EngineExample.routes.draw do
+ root :to => "foo#index"
+ resources :bars
+end
Please sign in to comment.
Something went wrong with that request. Please try again.