Commit 3131601f by Prem Sichanugrist

Add basic integration test using Cucumber

This test will generate a basic Rails application, include Paperclip
into Gemfile, and call basic `has_attached_file` in the model. This will
make sure that we're not messing up any of the configuration and
integration for our gem and the Rails framework.
parent ae781ac8
......@@ -4,7 +4,9 @@ rvm:
- ree
- rbx-2.0
script: "bundle exec rake clean test"
before_script: "sudo ntpdate -ub ntp.ubuntu.com pool.ntp.org; true"
script: "bundle exec rake clean test cucumber"
gemfile:
- gemfiles/rails2.gemfile
- gemfiles/rails3.gemfile
......
appraise "rails2" do
gem "rails", "~> 2.3.14"
gem "paperclip", :path => "../"
end
appraise "rails3" do
gem "rails", "~> 3.0.10"
gem "paperclip", :path => "../"
end
appraise "rails3_1" do
gem "rails", "~> 3.1.0"
gem "paperclip", :path => "../"
end
......@@ -2,6 +2,7 @@ source "http://rubygems.org"
gem "activerecord", :require => "active_record"
gem "appraisal"
gem "aruba"
gem "aws-s3", :require => "aws/s3"
gem "bundler"
gem "cocaine", "~>0.2"
......@@ -11,11 +12,11 @@ gem "mime-types"
gem "mocha"
gem "rake"
gem "rdoc", :require => false
gem "capybara"
gem "cucumber", "~> 1.0.0"
gem "shoulda"
gem "sqlite3", "~>1.3.4"
# This is for Rails 3.1
gem "sprockets", "~> 2.0.0.beta.13", :require => false
gem "fakeweb", :require => false
# gem "ruby-debug", :platform => :ruby_18
# gem "ruby-debug19", :platform => :ruby_19
GEM
remote: http://rubygems.org/
specs:
activerecord (2.3.12)
activesupport (= 2.3.12)
activesupport (2.3.12)
appraisal (0.3.5)
aruba (~> 0.3.6)
bundler
rake
aruba (0.3.7)
childprocess (>= 0.1.9)
cucumber (>= 0.10.5)
rspec (>= 2.6.0)
aws-s3 (0.6.2)
builder
mime-types
xml-simple
bouncy-castle-java (1.5.0146.1)
builder (3.0.0)
childprocess (0.1.9)
ffi (~> 1.0.6)
cocaine (0.2.0)
cucumber (0.10.5)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (~> 2.4.0)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
diff-lcs (1.1.2)
excon (0.6.3)
ffi (1.0.9)
ffi (1.0.9-java)
fog (0.8.2)
builder
excon (~> 0.6.1)
formatador (>= 0.1.3)
json
mime-types
net-ssh (>= 2.1.3)
nokogiri (>= 1.4.4)
ruby-hmac
formatador (0.1.4)
gherkin (2.4.5)
json (>= 1.4.6)
gherkin (2.4.5-java)
json (>= 1.4.6)
hike (1.2.0)
jruby-openssl (0.7.4)
bouncy-castle-java
json (1.5.3)
json (1.5.3-java)
mime-types (1.16)
mocha (0.9.12)
net-ssh (2.1.4)
nokogiri (1.4.4)
nokogiri (1.4.4-java)
weakling (>= 0.0.3)
rack (1.3.2)
rake (0.9.2)
rdoc (3.8)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
rspec-mocks (~> 2.6.0)
rspec-core (2.6.4)
rspec-expectations (2.6.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.6.0)
ruby-hmac (0.4.0)
shoulda (2.11.3)
sprockets (2.0.0.beta.13)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
term-ansicolor (1.0.5)
tilt (1.3.2)
weakling (0.0.4-java)
xml-simple (1.0.16)
PLATFORMS
java
ruby
DEPENDENCIES
activerecord
appraisal
aws-s3
bundler
cocaine (~> 0.2)
fog
jruby-openssl
mime-types
mocha
rake
rdoc
shoulda
sprockets (~> 2.0.0.beta.13)
sqlite3 (~> 1.3.4)
......@@ -5,6 +5,7 @@ require 'bundler/setup'
require 'rake'
require 'rake/testtask'
require 'rdoc/task'
require 'cucumber/rake/task'
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require 'paperclip'
......@@ -14,7 +15,7 @@ task :default => [:clean, 'appraisal:install', :all]
desc 'Test the paperclip plugin under all supported Rails versions.'
task :all do |t|
exec('rake appraisal test')
exec('rake appraisal test cucumber')
end
desc 'Test the paperclip plugin.'
......@@ -24,6 +25,11 @@ Rake::TestTask.new(:test) do |t|
t.verbose = true
end
desc 'Run integration test'
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w{--format progress}
end
desc 'Start an IRB session with all necessary files required.'
task :shell do |t|
chdir File.dirname(__FILE__)
......
Feature: Running paperclip in a Rails app
Scenario: Basic utilization
Given I have a rails application
And I save the following as "app/models/user.rb"
"""
class User < ActiveRecord::Base
has_attached_file :avatar
end
"""
When I visit /users/new
And I fill in "user_name" with "something"
And I attach the file "test/fixtures/5k.png" to "user_avatar"
And I press "Submit"
Then I should see "Name: something"
And I should see an image with a path of "/system/avatars/1/original/5k.png"
And the file at "/system/avatars/1/original/5k.png" is the same as "test/fixtures/5k.png"
Feature: Rails integration
Background:
Given I generate a new rails application
And I run a rails generator to generate a "User" scaffold with "name:string"
And I run a paperclip generator to add a paperclip "attachment" to the "User" model
And I run a migration
And I update my new user view to include the file upload field
And I update my user view to include the attachment
Scenario: Filesystem integration test
Given I add this snippet to the User model:
"""
has_attached_file :attachment
"""
And I start the rails application
When I go to the new user page
And I fill in "Name" with "something"
And I attach the file "test/fixtures/5k.png" to "Attachment"
And I press "Submit"
Then I should see "Name: something"
And I should see an image with a path of "/system/attachments/1/original/5k.png"
And the file at "/system/attachments/1/original/5k.png" should be the same as "test/fixtures/5k.png"
Scenario: S3 Integration test
Given I add this snippet to the User model:
"""
has_attached_file :attachment,
:storage => :s3,
:path => "/:attachment/:id/:style/:filename",
:s3_credentials => Rails.root.join("config/s3.yml")
"""
And I write to "config/s3.yml" with:
"""
bucket: paperclip
access_key_id: access_key
secret_access_key: secret_key
"""
And I start the rails application
When I go to the new user page
And I fill in "Name" with "something"
And I attach the file "test/fixtures/5k.png" to "Attachment" on S3
And I press "Submit"
Then I should see "Name: something"
And I should see an image with a path of "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png"
And the file at "http://s3.amazonaws.com/paperclip/attachments/1/original/5k.png" should be uploaded to S3
Feature: Running paperclip in a Rails app using basic S3 support
Scenario: Basic utilization
Given I have a rails application
And I save the following as "app/models/user.rb"
"""
class User < ActiveRecord::Base
has_attached_file :avatar,
:storage => :s3,
:path => "/:attachment/:id/:style/:filename",
:s3_credentials => Rails.root.join("config/s3.yml")
end
"""
And I validate my S3 credentials
And I save the following as "config/s3.yml"
"""
bucket: <%= ENV['PAPERCLIP_TEST_BUCKET'] || 'paperclip' %>
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
"""
When I visit /users/new
And I fill in "user_name" with "something"
And I attach the file "test/fixtures/5k.png" to "user_avatar"
And I press "Submit"
Then I should see "Name: something"
And I should see an image with a path of "http://s3.amazonaws.com/paperclip/avatars/1/original/5k.png"
And the file at "http://s3.amazonaws.com/paperclip/avatars/1/original/5k.png" is the same as "test/fixtures/5k.png"
......@@ -10,5 +10,6 @@ Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
visit(web_file)
page.body
end
actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
actual.should == expected
end
Given "I have a rails application" do
Given /^I generate a new rails application$/ do
steps %{
Given I generate a rails application
And this plugin is available
And I have a "users" resource with "name:string"
When I run `bundle exec #{new_application_command} #{APP_NAME}`
And I cd to "#{APP_NAME}"
And I turn off class caching
Given I save the following as "app/models/user.rb"
And I write to "Gemfile" with:
"""
class User < ActiveRecord::Base
end
"""
And I save the following as "config/s3.yml"
"""
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
bucket: paperclip
"""
And I save the following as "app/views/users/new.html.erb"
"""
<% form_for @user, :html => { :multipart => true } do |f| %>
<%= f.text_field :name %>
<%= f.file_field :avatar %>
<%= submit_tag "Submit" %>
<% end %>
source "http://rubygems.org"
gem "rails", "#{framework_version}"
gem "sqlite3"
gem "capybara"
gem "gherkin"
gem "aws-s3"
"""
And I save the following as "app/views/users/show.html.erb"
And I configure the application to use "paperclip" from this project
And I reset Bundler environment variable
And I successfully run `bundle install --local`
}
end
Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
Given %[I successfully run `bundle exec #{generator_command} scaffold #{model_name} #{attributes}`]
end
Given /^I run a paperclip generator to add a paperclip "([^"]*)" to the "([^"]*)" model$/ do |attachment_name, model_name|
Given %[I successfully run `bundle exec #{generator_command} paperclip #{model_name} #{attachment_name}`]
end
Given /^I run a migration$/ do
Given %[I successfully run `bundle exec rake db:migrate`]
end
Given /^I update my new user view to include the file upload field$/ do
if framework_version?("3")
steps %{
Given I overwrite "app/views/users/new.html.erb" with:
"""
<%= form_for @user, :html => { :multipart => true } do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :attachment %>
<%= f.file_field :attachment %>
<%= submit_tag "Submit" %>
<% end %>
"""
}
else
steps %{
Given I overwrite "app/views/users/new.html.erb" with:
"""
<% form_for @user, :html => { :multipart => true } do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :attachment %>
<%= f.file_field :attachment %>
<%= submit_tag "Submit" %>
<% end %>
"""
}
end
end
Given /^I update my user view to include the attachment$/ do
steps %{
Given I overwrite "app/views/users/show.html.erb" with:
"""
<p>Name: <%= @user.name %></p>
<p>Avatar: <%= image_tag @user.avatar.url %></p>
<p>Attachment: <%= image_tag @user.attachment.url %></p>
"""
And I run "script/generate paperclip user avatar"
And the rails application is prepped and running
}
end
Given %r{I generate a rails application} do
FileUtils.rm_rf TEMP_ROOT
FileUtils.mkdir_p TEMP_ROOT
Dir.chdir(TEMP_ROOT) do
`rails _2.3.8_ #{APP_NAME}`
Given /^I add this snippet to the User model:$/ do |snippet|
file_name = "app/models/user.rb"
in_current_dir do
content = File.read(file_name)
File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
end
end
When %r{I save the following as "([^"]*)"} do |path, string|
FileUtils.mkdir_p(File.join(CUC_RAILS_ROOT, File.dirname(path)))
File.open(File.join(CUC_RAILS_ROOT, path), 'w') { |file| file.write(string) }
Given /^I start the rails application$/ do
in_current_dir do
require "./config/environment"
require "capybara/rails"
end
end
Given /^I reload my application$/ do
Rails::Application.reload!
end
When %r{I turn off class caching} do
Dir.chdir(CUC_RAILS_ROOT) do
in_current_dir do
file = "config/environments/test.rb"
config = IO.read(file)
config.gsub!(%r{^\s*config.cache_classes.*$},
......@@ -56,35 +99,74 @@ When %r{I turn off class caching} do
end
end
When %r{the rails application is prepped and running$} do
When "I reset the database"
When "the rails application is running"
Given /^I update my application to use Bundler$/ do
if framework_version?("2")
boot_config_template = File.read('features/support/fixtures/boot_config.txt')
preinitializer_template = File.read('features/support/fixtures/preinitializer.txt')
gemfile_template = File.read('features/support/fixtures/gemfile.txt')
in_current_dir do
content = File.read("config/boot.rb").sub(/Rails\.boot!/, boot_config_template)
File.open("config/boot.rb", "w") { |file| file.write(content) }
File.open("config/preinitializer.rb", "w") { |file| file.write(preinitializer_template) }
File.open("Gemfile", "w") { |file| file.write(gemfile_template.sub(/RAILS_VERSION/, framework_version)) }
end
end
end
When %r{I reset the database} do
When %{I run "rake db:drop db:create db:migrate"}
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
expected = IO.read(path)
actual = if web_file.match %r{^https?://}
Net::HTTP.get(URI.parse(web_file))
else
visit(web_file)
page.source
end
actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
actual.should == expected
end
When %r{the rails application is running} do
Dir.chdir(CUC_RAILS_ROOT) do
require "config/environment"
require "capybara/rails"
end
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
steps %{And I run `bundle install --local`}
end
When %r{this plugin is available} do
$LOAD_PATH << "#{PROJECT_ROOT}/lib"
require 'paperclip'
When %{I save the following as "vendor/plugins/paperclip/rails/init.rb"},
IO.read("#{PROJECT_ROOT}/rails/init.rb")
When /^I configure the application to use "([^\"]+)"$/ do |gem_name|
append_to_gemfile "gem '#{gem_name}'"
end
When %r{I run "([^"]*)"} do |command|
Dir.chdir(CUC_RAILS_ROOT) do
`#{command}`
When /^I append gems from Appraisal Gemfile$/ do
File.read(ENV['BUNDLE_GEMFILE']).split(/\n/).each do |line|
if line =~ /^gem "(?!rails|appraisal)/
append_to_gemfile line.strip
end
end
end
When %r{I have a "([^"]*)" resource with "([^"]*)"} do |resource, fields|
When %{I run "script/generate scaffold #{resource} #{fields}"}
When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname|
comment_out_gem_in_gemfile gemname
end
module FileHelpers
def append_to(path, contents)
in_current_dir do
File.open(path, "a") do |file|
file.puts
file.puts contents
end
end
end
def append_to_gemfile(contents)
append_to('Gemfile', contents)
end
def comment_out_gem_in_gemfile(gemname)
in_current_dir do
gemfile = File.read("Gemfile")
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
end
end
end
World(FileHelpers)
Given /I validate my S3 credentials/ do
key = ENV['AWS_ACCESS_KEY_ID']
secret = ENV['AWS_SECRET_ACCESS_KEY']
key.should_not be_nil
secret.should_not be_nil
When /^I attach the file "([^"]*)" to "([^"]*)" on S3$/ do |file_path, field|
definition = User.attachment_definitions[field.downcase.to_sym]
path = "http://s3.amazonaws.com/paperclip#{definition[:path]}"
path.gsub!(':filename', File.basename(file_path))
path.gsub!(/:([^\/\.]+)/) do |match|
"([^\/\.]+)"
end
FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
When "I attach the file \"#{file_path}\" to \"#{field}\""
end
assert_credentials(key, secret)
Then /^the file at "([^"]*)" should be uploaded to S3$/ do |url|
FakeWeb.registered_uri?(:put, url)
end
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
# It is recommended to regenerate this file in the future when you upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a new file
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
# TL;DR: YOU SHOULD DELETE THIS FILE
#
# This file was generated by Cucumber-Rails and is only here to get you a head start
# These step definitions are thin wrappers around the Capybara/Webrat API that lets you
# visit pages, interact with widgets and make assertions about page content.
#
# If you use these step definitions as basis for your features you will quickly end up
# with features that are:
#
# * Hard to maintain
# * Verbose to read
#
# A much better approach is to write your own higher level step definitions, following
# the advice in the following blog posts:
#
# * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
# * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
# * http://elabs.se/blog/15-you-re-cuking-it-wrong
#
require 'uri'
require 'cgi'
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
module WithinHelpers
def with_scope(locator)
locator ? within(locator) { yield } : yield
locator ? within(*selector_for(locator)) { yield } : yield
end
end
World(WithinHelpers)
# Single-line step scoper
When /^(.*) within (.*[^:])$/ do |step, parent|
with_scope(parent) { When step }
end
# Multi-line step scoper
When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
with_scope(parent) { When "#{step}:", table_or_string }
end
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
end
......@@ -24,32 +49,20 @@ When /^(?:|I )go to (.+)$/ do |page_name|
visit path_to(page_name)
end
When /^(?:|I )visit (\/.+)$/ do |page_path|
visit page_path
When /^(?:|I )press "([^"]*)"$/ do |button|
click_button(button)
end
When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
with_scope(selector) do
click_button(button)
end
When /^(?:|I )follow "([^"]*)"$/ do |link|
click_link(link)
end
When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
with_scope(selector) do
click_link(link)
end
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
with_scope(selector) do
fill_in(field, :with => value)
end
end
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
with_scope(selector) do
fill_in(field, :with => value)
end
When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
fill_in(field, :with => value)
end
# Use this to fill in an entire form with data from a table. Example:
......@@ -63,119 +76,92 @@ end
# TODO: Add support for checkbox, select og option
# based on naming conventions.
#
When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
with_scope(selector) do
fields.rows_hash.each do |name, value|
When %{I fill in "#{name}" with "#{value}"}
end
When /^(?:|I )fill in the following:$/ do |fields|
fields.rows_hash.each do |name, value|
When %{I fill in "#{name}" with "#{value}"}
end
end
When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
with_scope(selector) do
select(value, :from => field)
end
When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
select(value, :from => field)
end
When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
with_scope(selector) do
check(field)
end
When /^(?:|I )check "([^"]*)"$/ do |field|
check(field)
end
When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
with_scope(selector) do
uncheck(field)
end
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
uncheck(field)
end
When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
with_scope(selector) do
choose(field)
end
When /^(?:|I )choose "([^"]*)"$/ do |field|
choose(field)
end
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
with_scope(selector) do
attach_file(field, path)
end
end
Then /^(?:|I )should see JSON:$/ do |expected_json|
require 'json'
expected = JSON.pretty_generate(JSON.parse(expected_json))
actual = JSON.pretty_generate(JSON.parse(response.body))
expected.should == actual
When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
attach_file(field, File.expand_path(path))
end
Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
with_scope(selector) do
if page.respond_to? :should
page.should have_content(text)
else
assert page.has_content?(text)
end
Then /^(?:|I )should see "([^"]*)"$/ do |text|
if page.respond_to? :should
page.should have_content(text)
else
assert page.has_content?(text)
end
end
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
regexp = Regexp.new(regexp)
with_scope(selector) do
if page.respond_to? :should
page.should have_xpath('//*', :text => regexp)
else
assert page.has_xpath?('//*', :text => regexp)
end
if page.respond_to? :should
page.should have_xpath('//*', :text => regexp)
else
assert page.has_xpath?('//*', :text => regexp)
end
end
Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
with_scope(selector) do
if page.respond_to? :should
page.should have_no_content(text)
else
assert page.has_no_content?(text)
end
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
if page.respond_to? :should
page.should have_no_content(text)
else
assert page.has_no_content?(text)
end
end
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
regexp = Regexp.new(regexp)
with_scope(selector) do
if page.respond_to? :should
page.should have_no_xpath('//*', :text => regexp)
else
assert page.has_no_xpath?('//*', :text => regexp)
end
if page.respond_to? :should
page.should have_no_xpath('//*', :text => regexp)
else
assert page.has_no_xpath?('//*', :text => regexp)
end
end
Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
with_scope(selector) do
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
with_scope(parent) do
field = find_field(field)
field_value = (field.tag_name == 'textarea') ? field.text : field.value
if field_value.respond_to? :should
field_value.should =~ /#{value}/
if field.value.respond_to? :should
field.value.should =~ /#{value}/
else
assert_match(/#{value}/, field_value)
assert_match(/#{value}/, field.value)
end
end
end
Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
with_scope(selector) do
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
with_scope(parent) do
field = find_field(field)
field_value = (field.tag_name == 'textarea') ? field.text : field.value
if field_value.respond_to? :should_not
field_value.should_not =~ /#{value}/
if field.value.respond_to? :should_not
field.value.should_not =~ /#{value}/
else
assert_no_match(/#{value}/, field_value)
assert_no_match(/#{value}/, field.value)
end
end
end
Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
with_scope(selector) do
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
with_scope(parent) do
field_checked = find_field(label)['checked']
if field_checked.respond_to? :should
field_checked.should be_true
......@@ -185,8 +171,8 @@ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |labe
end
end
Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
with_scope(selector) do
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
with_scope(parent) do
field_checked = find_field(label)['checked']
if field_checked.respond_to? :should
field_checked.should be_false
......@@ -218,10 +204,6 @@ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
end
end
Then /^I save and open the page$/ do
save_and_open_page
end
Then /^show me the page$/ do
save_and_open_page
end
require 'aruba/cucumber'
require 'capybara/cucumber'
require 'test/unit/assertions'
World(Test::Unit::Assertions)
Before do
@aruba_timeout_seconds = 120
end
require 'fake_web'
FakeWeb.allow_net_connect = false
class Rails::Boot
def run
load_initializer
Rails::Initializer.class_eval do
def load_gems
@bundler_loaded ||= Bundler.require :default, Rails.env
end
end
Rails::Initializer.run(:set_load_path)
end
end
Rails.boot!
source "http://rubygems.org"
gem "rails", "RAILS_VERSION"
gem "rdoc"
gem "sqlite3"
begin
require "rubygems"
require "bundler"
rescue LoadError
raise "Could not load the bundler gem. Install it with `gem install bundler`."
end
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
"Run `gem install bundler` to upgrade."
end
begin
# Set up load paths for all bundled gems
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
Bundler.setup
rescue Bundler::GemNotFound
raise RuntimeError, "Bundler couldn't find some gems." +
"Did you run `bundle install`?"
end
......@@ -8,17 +8,10 @@ module NavigationHelpers
def path_to(page_name)
case page_name
when /the new user page/
'/users/new'
when /the home\s?page/
'/'
# Add more mappings here.
# Here is an example that pulls values out of the Regexp:
#
# when /^(.*)'s profile page$/i
# user_profile_path(User.find_by_login($1))
when /the new user page/
'/users/new'
else
begin
page_name =~ /the (.*) page/
......
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
TEMP_ROOT = File.join(PROJECT_ROOT, 'tmp').freeze
APP_NAME = 'testapp'.freeze
CUC_RAILS_ROOT = File.join(TEMP_ROOT, APP_NAME).freeze
BUNDLE_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE)
ORIGINAL_BUNDLE_VARS = Hash[ENV.select{ |key,value| BUNDLE_ENV_VARS.include?(key) }]
ENV['RAILS_ENV'] = 'test'
Before do
ENV['BUNDLE_GEMFILE'] = File.join(Dir.pwd, ENV['BUNDLE_GEMFILE']) unless ENV['BUNDLE_GEMFILE'].start_with?(Dir.pwd)
@framework_version = nil
end
After do
ORIGINAL_BUNDLE_VARS.each_pair do |key, value|
ENV[key] = value
end
end
When /^I reset Bundler environment variable$/ do
BUNDLE_ENV_VARS.each do |key|
ENV[key] = nil
end
end
module RailsCommandHelpers
def framework_version?(version_string)
framework_version =~ /^#{version_string}/
end
def framework_version
@framework_version ||= `rails -v`[/^Rails (.+)$/, 1]
end
def new_application_command
framework_version?("3") ? "rails new" : "rails"
end
def generator_command
framework_version?("3") ? "script/rails generate" : "script/generate"
end
end
World(RailsCommandHelpers)
module AWSS3Methods
def load_s3
begin
require 'aws/s3'
rescue LoadError => e
fail "You do not have aws-s3 installed."
end
end
def assert_credentials(key, secret)
load_s3
begin
AWS::S3::Base.establish_connection!(
:access_key_id => key,
:secret_access_key => secret
)
AWS::S3::Service.buckets
rescue AWS::S3::ResponseError => e
fail "Could not connect using AWS credentials in AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. " +
"Please make sure these are set in your environment."
end
end
end
World(AWSS3Methods)
module HtmlSelectorsHelpers
# Maps a name to a selector. Used primarily by the
#
# When /^(.+) within (.+)$/ do |step, scope|
#
# step definitions in web_steps.rb
#
def selector_for(locator)
case locator
when "the page"
"html > body"
else
raise "Can't find mapping from \"#{locator}\" to a selector.\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end
World(HtmlSelectorsHelpers)
......@@ -4,6 +4,7 @@ source "http://rubygems.org"
gem "activerecord", :require=>"active_record"
gem "appraisal"
gem "aruba"
gem "aws-s3", :require=>"aws/s3"
gem "bundler"
gem "cocaine", "~>0.2"
......@@ -13,8 +14,11 @@ gem "mime-types"
gem "mocha"
gem "rake"
gem "rdoc", :require=>false
gem "capybara"
gem "cucumber", "~> 1.0.0"
gem "shoulda"
gem "sqlite3", "~>1.3.4"
gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "fakeweb", :require=>false
gem "rails", "~> 2.3.14"
gem "paperclip", :path=>"../"
......@@ -4,6 +4,7 @@ source "http://rubygems.org"
gem "activerecord", :require=>"active_record"
gem "appraisal"
gem "aruba"
gem "aws-s3", :require=>"aws/s3"
gem "bundler"
gem "cocaine", "~>0.2"
......@@ -13,8 +14,11 @@ gem "mime-types"
gem "mocha"
gem "rake"
gem "rdoc", :require=>false
gem "capybara"
gem "cucumber", "~> 1.0.0"
gem "shoulda"
gem "sqlite3", "~>1.3.4"
gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "fakeweb", :require=>false
gem "rails", "~> 3.0.10"
gem "paperclip", :path=>"../"
......@@ -4,6 +4,7 @@ source "http://rubygems.org"
gem "activerecord", :require=>"active_record"
gem "appraisal"
gem "aruba"
gem "aws-s3", :require=>"aws/s3"
gem "bundler"
gem "cocaine", "~>0.2"
......@@ -13,8 +14,11 @@ gem "mime-types"
gem "mocha"
gem "rake"
gem "rdoc", :require=>false
gem "capybara"
gem "cucumber", "~> 1.0.0"
gem "shoulda"
gem "sqlite3", "~>1.3.4"
gem "sprockets", "~> 2.0.0.beta.13", :require=>false
gem "fakeweb", :require=>false
gem "rails", "~> 3.1.0"
gem "paperclip", :path=>"../"
......@@ -33,4 +33,6 @@ spec = Gem::Specification.new do |s|
s.add_development_dependency 'mocha'
s.add_development_dependency 'aws-s3'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'cucumber'
s.add_development_dependency 'capybara'
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment