Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #630 from alindeman/capybara_url_helpers

Capybara feature specs may use Rails URL helpers
  • Loading branch information...
commit fd25838a39321708d6cdaaeb493274f119db1a19 2 parents 4211c07 + 96e1c33
@alindeman alindeman authored
View
1  lib/rspec/rails.rb
@@ -13,5 +13,6 @@
require 'rspec/rails/mocks'
require 'rspec/rails/module_inclusion'
require 'rspec/rails/example'
+require 'rspec/rails/url_helpers'
require 'rspec/rails/vendor/capybara'
require 'rspec/rails/vendor/webrat'
View
19 lib/rspec/rails/url_helpers.rb
@@ -0,0 +1,19 @@
+module RSpec::Rails
+ module UrlHelpers
+ DEFAULT_HOST = "www.example.com"
+
+ def self.included(base)
+ app = ::Rails.application
+ if app.respond_to?(:routes)
+ base.class_eval do
+ include app.routes.url_helpers if app.routes.respond_to?(:url_helpers)
+ include app.routes.mounted_helpers if app.routes.respond_to?(:mounted_helpers)
+ end
+
+ if base.respond_to?(:default_url_options)
+ base.default_url_options[:host] ||= ::RSpec::Rails::UrlHelpers::DEFAULT_HOST
+ end
+ end
+ end
+ end
+end
View
4 lib/rspec/rails/vendor/capybara.rb
@@ -35,5 +35,9 @@
c.include Capybara, :type => :request
c.include Capybara, :type => :controller
end
+
+ c.include RSpec::Rails::UrlHelpers, :type => :feature, :example_group => {
+ :file_path => c.escaped_path(%w[spec features])
+ }
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.