Skip to content

Instantly share code, notes, and snippets.

@lachie lachie/Rakefile
Created Sep 2, 2010

Embed
What would you like to do?
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
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
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
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
You can’t perform that action at this time.