Created
September 2, 2010 22:38
-
-
Save lachie/563094 to your computer and use it in GitHub Desktop.
This file contains 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 'eg.helper' | |
require 'capybara' | |
require 'capybara/rails' | |
require 'capybara/dsl' | |
# Capybara.default_driver = :rails | |
eg.helpers do | |
include Capybara | |
def login_as(email, password) | |
fill_in 'Email', :with => email | |
fill_in 'Password', :with => password | |
click_button("Log in") | |
end | |
def check_flash(type, message) | |
Assert(find(:css, ".flash.#{type}").text.include?(message)) | |
end | |
def check_admin_flash(type, message) | |
Assert(find(:css, ".message.#{type}").text.include?(message)) | |
end | |
def admin? | |
Assert(find(:css, 'title').text.include?("Compliance Hound Administration")) | |
end | |
# etc | |
end |
This file contains 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
ENV["RAILS_ENV"] = "test" | |
require File.expand_path('../../config/environment', __FILE__) | |
require 'pp' | |
require 'exemplor' | |
eg.helpers do | |
def user(name,role) | |
... factory up a user | |
end | |
end |
This file contains 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 'eg.acceptance.helper' | |
eg.setup do | |
User.delete_all | |
Location.delete_all | |
user('sam','admin') | |
end | |
eg 'visit admin page as an administrator and login' do | |
visit '/admin/tasks' | |
login_as("sam", "password") | |
check_admin_flash("success", "Signed in successfully") | |
admin? | |
end | |
eg 'another eg' do | |
body # a string of the page | |
page.response_headers | |
page.status_code | |
page.current_url | |
# etc | |
end |
This file contains 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
task :eg => %w[eg:examples eg:acceptance] | |
namespace :eg do | |
ExampleRoot = Rails.root+'examples' | |
task :examples => :test_env do | |
in_example_root do | |
FileList.new(ExampleRoot+'*.eg.rb').each {|eg| run_eg eg } | |
end | |
end | |
task :acceptance => :test_env do | |
in_example_root do | |
FileList.new(ExampleRoot+'acceptance/*.eg.rb').each {|eg| run_eg eg } | |
end | |
end | |
task :test_env do | |
ENV['RAILS_ENV'] = ::RAILS_ENV = 'test' | |
Rake::Task['environment'].invoke | |
end | |
def run_eg(eg) | |
print "running #{eg_name = File.basename(eg,'.eg.rb')} examples" | |
if eg[/acceptance/] | |
puts " (acceptance)" | |
else | |
puts | |
end | |
begin | |
ruby eg | |
rescue | |
puts "#{eg_name} examples failed" | |
end | |
puts | |
end | |
def in_example_root(&blk) | |
Dir.chdir(ExampleRoot,&blk) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment