Over a million developers have joined DZone.

Acceptance Testing For Rails

·
Make sure you have following gems in your Gemfile:


  gem "rspec", "2.0.1"
  gem "rspec-rails", "2.0.1"
  gem "capybara", ">= 0.4.1.1"
  gem "database_cleaner", ">= 0.6.6" 


Add spec/support/acceptance_example_group.rb:

require 'action_dispatch'
require 'capybara/rails'
require 'capybara/rspec'
require 'capybara/dsl'

module AcceptanceExampleGroup
  extend ActiveSupport::Concern

  include RSpec::Rails::RequestExampleGroup
  include Rack::Test::Methods

  included do
    metadata[:type] = :acceptance
  end
end

RSpec.configure do |config|
  config.include AcceptanceExampleGroup,
     :example_group => { :file_path => /\bspec\/acceptance\// }

  config.use_transactional_fixtures = false

  config.before(:suite) do
    DatabaseCleaner.strategy = :deletion
    DatabaseCleaner.clean_with :truncation
  end

  config.before(:each) do
    if example.metadata[:js]
      Capybara.current_driver = :selenium
      DatabaseCleaner.strategy = :truncation
    else
      DatabaseCleaner.strategy = :transaction
      DatabaseCleaner.start
    end
  end

  config.after(:each) do
    Capybara.use_default_driver if example.metadata[:js]
    DatabaseCleaner.clean
  end
end 


Delete line from spec/spec_helper.rb

  config.use_transactional_fixtures = true


Create spec/acceptance/some_acceptance_spec.rb

require 'spec_helper'

describe "some feature", :js => true do

  it "..." do
   visit "/"
  end
end


No you may create your acceptance tests.

===============================

Consider stake gem as alternative
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}