Permalink
Browse files

Merge pull request #630 from alindeman/capybara_url_helpers

Capybara feature specs may use Rails URL helpers
  • Loading branch information...
2 parents 4211c07 + 96e1c33 commit fd25838a39321708d6cdaaeb493274f119db1a19 @alindeman alindeman committed Nov 6, 2012
Showing with 24 additions and 0 deletions.
  1. +1 −0 lib/rspec/rails.rb
  2. +19 −0 lib/rspec/rails/url_helpers.rb
  3. +4 −0 lib/rspec/rails/vendor/capybara.rb
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

0 comments on commit fd25838

Please sign in to comment.