Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Inherit from RSpec-Rails' RequestExampleGroup which already takes car…

…e of including Webrat/Capybara
  • Loading branch information...
commit 47a415d4addbf54dce6a08eed09ae8ddf7aaedc0 1 parent 6cb6a92
@cavalle authored
View
7 lib/rspec-2/rails/generators/install_generator.rb
@@ -2,9 +2,6 @@
module Steak
class InstallGenerator < Rails::Generators::Base
- class_option :webrat, :desc => 'Use Webrat.', :type => :boolean
- class_option :capybara, :desc => 'Use Capybara.', :type => :boolean
-
source_root File.join(File.dirname(__FILE__), 'templates')
desc <<-DESC
@@ -30,9 +27,5 @@ def manifest
copy_file "helpers.rb", "spec/acceptance/support/helpers.rb"
copy_file "paths.rb", "spec/acceptance/support/paths.rb"
end
-
- def driver
- @driver = options.webrat? ? 'webrat' : 'capybara'
- end
end
end
View
35 lib/rspec-2/rails/generators/templates/acceptance_helper.rb
@@ -1,38 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
require "steak"
-<%- if driver == 'webrat' %>
-require "webrat"
-
-Webrat.configure do |config|
- config.mode = :rack
-end
-
-module Steak::Webrat
- include Rack::Test::Methods
- include Webrat::Methods
- include Webrat::Matchers
-
- def app
- ::Rails.application
- end
-end
-
-RSpec.configuration.include Steak::Webrat, :type => :acceptance
-
-<%- else -%>
-require 'capybara/rails'
-
-module Steak::Capybara
- include Rack::Test::Methods
- include Capybara
-
- def app
- ::Rails.application
- end
-end
-
-RSpec.configuration.include Steak::Capybara, :type => :acceptance
-<%- end -%>
# Put your acceptance spec helpers inside /spec/acceptance/support
-Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
View
6 lib/rspec-2/steak.rb
@@ -6,6 +6,12 @@ def self.included(base)
base.instance_eval do
alias scenario example
alias background before
+
+ if defined?(RSpec::Rails)
+ include RSpec::Rails::RequestExampleGroup
+ include Rack::Test::Methods
+ metadata[:type] = :acceptance
+ end
end
end
end
View
2  spec/acceptance/rspec-1/acceptance_helper.rb
@@ -66,7 +66,7 @@ def steak_dir
File.expand_path(File.dirname(__FILE__) + "/../../../")
end
end
-
+
def self.gemset_create(gemset, *gems)
`rvm gemset create #{gemset}`
gems.each do |name|
View
14 spec/acceptance/rspec-2/acceptance_helper.rb
@@ -15,20 +15,20 @@ def create_spec(options)
end
def create_rails_app(options = {})
+ options[:browser_simulator] ||= "capybara"
+
path = File.join(Dir.tmpdir, String.random, "rails_app")
FileUtils.rm_rf path
run "rails new #{path}"
FileUtils.rm_rf path + '/public/index.html'
File.open(File.join(path, "Gemfile"), "a") do |file|
- file.write "\ngem 'rspec-rails', '>= 2.0.0.a9'\n" <<
- "gem 'capybara'\n" <<
- "gem 'webrat'\n"
+ file.write %{
+ gem 'rspec-rails', '>= 2.0.0.a9'
+ gem '#{options[:browser_simulator]}'
+ gem 'steak', :path => '#{File.expand_path(File.dirname(__FILE__) + '/../../..')}'
+ }
end
- File.open(File.join(path, "Gemfile"), "a") do |file|
- file.write "\ngem 'steak', :path => '#{File.expand_path(File.dirname(__FILE__) + '/../../..')}'\n"
- end
-
run "bundle install"
Dir.chdir path do
View
6 spec/acceptance/rspec-2/steak_install_generator_spec.rb
@@ -42,11 +42,7 @@
end
scenario "Running generator with webrat" do
- rails_app = create_rails_app(:setup_steak => false, :scaffold => :users)
-
- Dir.chdir rails_app do
- run "rails generate steak:install --webrat"
- end
+ rails_app = create_rails_app(:browser_simulator => :webrat, :scaffold => :users)
spec_file = create_spec :path => rails_app + "/spec/acceptance",
:content => <<-SPEC
Please sign in to comment.
Something went wrong with that request. Please try again.