Created
April 10, 2012 11:51
-
-
Save peterhellberg/2350832 to your computer and use it in GitHub Desktop.
Sinatra acceptance testing, using minitest/spec and capybara-webkit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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
thanks for this!