Skip to content

Commit

Permalink
Better testing: Rails 4 app
Browse files Browse the repository at this point in the history
  • Loading branch information
rsantamaria committed Sep 21, 2015
1 parent 0b585bb commit eb34cc5
Show file tree
Hide file tree
Showing 75 changed files with 933 additions and 268 deletions.
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
*.swp
**/*.swp
Gemfile.lock
gemfiles/rails_3_2.gemfile.lock
gemfiles/*.gemfile.lock

test_apps/rails_3_2/.bundle
test_apps/rails_3_2/Gemfile.lock
test_apps/rails_3_2/db/*.sqlite3
test_apps/rails_3_2/log/*.log
test_apps/rails_3_2/tmp
test_apps/rails_3_2/public/assets
test_apps/rails_3_2/public/assets
test_apps/rails_4/.bundle
test_apps/rails_4/Gemfile.lock
test_apps/rails_4/db/*.sqlite3
test_apps/rails_4/log/*.log
test_apps/rails_4/tmp
test_apps/rails_4/public/assets
5 changes: 5 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
appraise "rails_3_2" do
gem "rails", "3.2.13"
gem "paperclip", "3.4.0"
end

appraise "rails_4" do
gem "rails", "4.0.2"
gem "paperclip", "4.1.0"
end
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ If you're rendering it on ajax ensure to call init_papercrop() in js after loadi

### Running the Tests

We are using a dummy application to handle some of our test cases. You can find this in the `/test_app` directory and should be able to run this as a regular Rails 4 app _(using the `rails s` command)_ if you're interested in taking a look. You may need to create the mock database for the `test_app` before your tests will start to pass. This means you need to run `rake db:create db:migrate db:test:prepare` from within the `test_app` directory.
We are using dummy applications to handle some of our test cases with different Gemfiles using [Appraisal](https://github.com/thoughtbot/appraisal). You can find them in the `/test_apps` directory and should be able to run them as a regular Rails app _(using the `rails s` command)_ if you're interested in taking a look. You may need to create mock databases for the `test_apps` before your tests will start to pass. This means you need to run the classics `rake db:create db:migrate db:test:prepare` through appraisal from the root directory.

appraisal rails_3_2 rake db:create db:migrate
appraisal rails_4 rake db:create db:migrate

Append RAILS_ENV=test to both commands to prepare each database for testing

In order to fully test our gem, we needed to use [Selenium](http://docs.seleniumhq.org/download/). Getting this setup is beyond the scope of this Readme.

Once you have everything setup, you should be able `bundle exec rake` from the root directory have everything run. If you've installed Selenium properly, you should see an automated instance of your browser _(eg. Firefox)_ pop up and run through some of the integration tests.
Once you have everything setup, you should be able `appraisal rake` from the root directory have everything run. If you've installed Selenium properly, you should see an automated instance of your browser _(eg. Firefox)_ pop up and run through some of the integration tests.

That's all!

Expand Down
8 changes: 7 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

APP_RAKEFILE = File.expand_path("../test_apps/rails_3_2/Rakefile", __FILE__)
ENV["TEST_APP"] = if ENV["APPRAISAL_INITIALIZED"]
ENV["BUNDLE_GEMFILE"].split('/').last.split('.').first
else
"rails_4"
end

APP_RAKEFILE = File.expand_path("../test_apps/#{ENV["TEST_APP"]}/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'

task :default => :spec
8 changes: 8 additions & 0 deletions gemfiles/rails_4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "http://rubygems.org"

gem "rails", "4.0.2"
gem "paperclip", "4.1.0"

gemspec :path => "../"
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] = 'test'
require File.expand_path("../../test_apps/rails_3_2/config/environment", __FILE__)
ENV["TEST_APP"] ||= 'rails_4'

require File.expand_path("../../test_apps/#{ENV["TEST_APP"]}/config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'database_cleaner'
Expand Down
261 changes: 0 additions & 261 deletions test_apps/rails_3_2/README.rdoc

This file was deleted.

2 changes: 1 addition & 1 deletion test_apps/rails_3_2/app/views/landscapes/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
<%= f.file_field :picture %>
</div>
<div class="actions">
<%= f.submit %>
<%= f.submit %>
</div>
<% end %>
21 changes: 21 additions & 0 deletions test_apps/rails_4/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
source 'https://rubygems.org'

gem 'rails', '4.0.2'
gem 'sqlite3'
gem 'jquery-rails'
gem 'jbuilder', '~> 1.2'
gem 'paperclip', '4.1.0'
gem 'papercrop', :path => "../.."

group :assets do
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'therubyracer', platforms: :ruby
end

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end

6 changes: 6 additions & 0 deletions test_apps/rails_4/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Rails4::Application.load_tasks
Empty file.
Loading

0 comments on commit eb34cc5

Please sign in to comment.