Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created April 10, 2012 11:51
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save peterhellberg/2350832 to your computer and use it in GitHub Desktop.
Save peterhellberg/2350832 to your computer and use it in GitHub Desktop.
Sinatra acceptance testing, using minitest/spec and capybara-webkit
# encoding: utf-8
require_relative "spec_helper"
require_relative "../my_app.rb"
require 'capybara'
require 'capybara/dsl'
require 'capybara/webkit'
require 'capybara_minitest_spec'
Capybara.app = MyApp
Capybara.default_driver = :webkit
class MiniTest::Spec
include Capybara::DSL
end
class Capybara::Session
def params
Hash[*URI.parse(current_url).query.split(/\?|=|&/)]
end
end
source :rubygems
gem "sinatra", "~> 1.3.2"
group :test do
gem "minitest", "~> 2.10"
gem "rack-test", "~> 0.6.1"
gem "capybara", "~> 1.1"
gem "capybara-webkit", "~> 0.11"
gem "capybara_minitest_spec", "~> 0.2"
end
require_relative "acceptance_helper"
describe MyApp do
it "shows a site" do
visit '/'
fill_in 'q', :with => 'Test'
click_button 'Search'
page.must_have_content 'Test'
page.params['q'].must_equal 'Test'
end
end
%w{ rubygems bundler find rake/testtask}.each { |lib| require lib }
task :default => :spec
Rake::TestTask.new(:spec) do |t|
t.test_files = FileList['spec/*_spec.rb']
end
Rake::TestTask.new(:acceptance) do |t|
t.test_files = FileList['spec/*_acceptance.rb']
end
# encoding: UTF-8
require 'bundler'
Bundler.setup
Bundler.require
require 'minitest/pride'
require 'minitest/autorun'
require 'minitest/spec'
require 'rack/test'
class MiniTest::Spec
include Rack::Test::Methods
end
@oguzcanhuner
Copy link

thanks for this!

@sfsekaran
Copy link

Super useful. After a ton of searching, this is the only guide that worked. And--BONUS--there is zero text to read through. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment