Skip to content

Commit

Permalink
Merge pull request rspec#630 from alindeman/capybara_url_helpers
Browse files Browse the repository at this point in the history
Capybara feature specs may use Rails URL helpers
  • Loading branch information
alindeman committed Nov 6, 2012
2 parents 4211c07 + 96e1c33 commit fd25838
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rspec/rails.rb
Expand Up @@ -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'
19 changes: 19 additions & 0 deletions 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
4 changes: 4 additions & 0 deletions lib/rspec/rails/vendor/capybara.rb
Expand Up @@ -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.