Skip to content

Commit

Permalink
Out with the old, in with the new
Browse files Browse the repository at this point in the history
This commit is long overdue. The main change is to upgrade shoulda's
hard dependency on shoulda-matchers from 2.x to 3.x. Since this by
itself is a pretty consequential change, though, I also took the
opportunity to make some more at the same time that I think are
reasonable:

* Remove support for Rails 3, Rails 4.0, and Rails 4.1, since they have
  been end-of-lifed; support Rails 4.2-5.0 instead.
* Remove support for Ruby 1.9 and 2.0; support Ruby 2.1-2.4 instead.
* Remove support for RSpec, along with related Cucumber specs. People
  who use RSpec won't be using the `shoulda` gem -- they'll be using
  `shoulda-matchers` instead. There's already a good collection of
  integration specs there, so we don't need the tests here.

Please note that we are using the Rails Git repo to refer to 4.2 because
the latest release of 4.2 isn't compatible with Ruby 2.4 just yet (but
it's fixed on the 4-2-stable branch).
  • Loading branch information
mcmire committed Feb 3, 2017
1 parent b411932 commit b9353e2
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 125 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Gemfile.lock
coverage
doc
gemfiles
pkg
tags
test/*/log/*.log
Expand Down
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
language: ruby
sudo: false
cache: bundler
script: "bundle exec rake"
rvm:
- 1.9.3
- 2.0.0
- 2.1
- 2.2

- 2.2.6
- 2.3.3
- 2.4.0
gemfile:
- gemfiles/4.2.gemfile
- gemfiles/5.0.gemfile
23 changes: 13 additions & 10 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
appraise '3.0' do
gem 'rails', '3.0.12'
shared_dependencies = proc do
gem 'listen'
gem 'sass-rails'
gem 'sqlite3'
gem 'rspec', '~> 3.0'
gem 'shoulda-context'
gem 'shoulda-matchers', '~> 3.0'
end

appraise '3.1' do
gem 'rails', '3.1.4'
gem 'jquery-rails'
gem 'sass-rails'
appraise '4.2' do
instance_eval(&shared_dependencies)
gem 'rails', git: 'https://github.com/rails/rails.git', branch: '4-2-stable'
end

appraise '3.2' do
gem 'rails', '3.2.3'
gem 'jquery-rails'
gem 'sass-rails'
appraise '5.0' do
instance_eval(&shared_dependencies)
gem 'rails', '5.0.1'
end
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
source 'https://rubygems.org'

gemspec
gem 'appraisal', '~> 2.1'
gem 'rails', '>= 4.2', '< 6'
gem 'sqlite3', '~> 1.3.11'
gem 'rspec', '~> 3.0'
13 changes: 11 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@ require 'bundler/gem_tasks'
require 'cucumber/rake/task'
require 'appraisal'

def appraisal_in_use?
Bundler.default_gemfile.dirname ==
Pathname.new('../gemfiles').expand_path(__FILE__)
end

Cucumber::Rake::Task.new do |t|
t.fork = true
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
end

desc 'Test the plugin under all supported Rails versions.'
task :all => ["appraisal:cleanup", "appraisal:install"] do
exec('rake appraisal cucumber')
task :all do
if appraisal_in_use?
exec 'bundle exec rake cucumber --trace'
else
exec 'bundle exec appraisal install && appraisal rake --trace'
end
end

desc 'Default: run cucumber features'
Expand Down
54 changes: 18 additions & 36 deletions features/rails_integration.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@disable-bundler
Feature: integrate with Rails
Feature: Integrate with Rails

Background:
When I generate a new rails application
When I generate a new Rails application
And I write to "db/migrate/1_create_users.rb" with:
"""
class CreateUsers < ActiveRecord::Migration
Expand All @@ -24,24 +23,24 @@ Feature: integrate with Rails
"""
class ExamplesController < ApplicationController
def show
@example = 'hello'
flash['foo'] = 'bar'
render :nothing => true
end
end
"""
When I configure a wildcard route

Scenario: generate a rails application and use matchers in Test::Unit
When I configure the application to use shoulda
And I write to "test/unit/user_test.rb" with:
Scenario: Generate a Rails application and use matchers under Minitest
When I configure the application to use Shoulda
And I write to "test/models/user_test.rb" with:
"""
require 'test_helper'
class UserTest < ActiveSupport::TestCase
should validate_presence_of(:name)
end
"""
When I write to "test/functional/examples_controller_test.rb" with:
When I write to "test/controllers/examples_controller_test.rb" with:
"""
require 'test_helper'
Expand All @@ -50,38 +49,21 @@ Feature: integrate with Rails
get :show
end
should set_flash[:foo].to('bar')
should respond_with(:success)
should assign_to(:example)
end
"""
When I successfully run `bundle exec rake test TESTOPTS='-v' --trace`
Then the output should contain "1 tests, 1 assertions, 0 failures, 0 errors"
And the output should contain "2 tests, 2 assertions, 0 failures, 0 errors"
And the output should contain "User should require name to be set"
And the output should contain "ExamplesController should assign @example"

Scenario: generate a rails application and use matchers in Rspec
When I configure the application to use rspec-rails
And I configure the application to use shoulda-matchers
And I run the rspec generator
And I write to "spec/models/user_spec.rb" with:
When I successfully run the "test" task
Then the output should contain:
"""
require 'spec_helper'
describe User do
it { should validate_presence_of(:name) }
end
ExamplesController should respond with 200.
"""
When I write to "spec/controllers/examples_controller_spec.rb" with:
And the output should contain:
"""
require 'spec_helper'
describe ExamplesController, "show" do
before { get :show }
it { should assign_to(:example) }
end
ExamplesController should should set flash[:foo] to "bar".
"""
And the output should contain:
"""
User should validate that :name cannot be empty/falsy.
"""
When I successfully run `bundle exec rake spec SPEC_OPTS=-fs --trace`
Then the output should contain "2 examples, 0 failures"
And the output should contain "should require name to be set"
And the output should contain "should assign @example"
And the output should indicate that 3 tests were run successfully
84 changes: 37 additions & 47 deletions features/step_definitions/rails_steps.rb
Original file line number Diff line number Diff line change
@@ -1,77 +1,67 @@
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
APP_NAME = 'testapp'.freeze

When /^I generate a new rails application$/ do
When 'I generate a new Rails application' do
steps %{
When I run `bundle exec rails new #{APP_NAME}`
When I run `bundle exec rails new #{APP_NAME} --skip-bundle --no-rc`
And I cd to "#{APP_NAME}"
And I write to "Gemfile" with:
"""
source "http://rubygems.org"
gem 'rails', '3.0.12'
source 'https://rubygems.org'
gem 'rails', '#{rails_version}'
gem 'sqlite3'
"""
And I successfully run `bundle install --local`
}
end

When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
append_to_gemfile "gem '#{name}', :path => '#{PROJECT_ROOT}'"
append_to_gemfile "gem '#{name}', path: '#{PROJECT_ROOT}'"
steps %{And I run `bundle install --local`}
end

When /^I run the rspec generator$/ do
steps %{
When I successfully run `rails generate rspec:install`
}
end

When /^I configure the application to use rspec\-rails$/ do
append_to_gemfile "gem 'rspec-rails'"
When 'I configure the application to use Shoulda' do
append_to_gemfile "gem 'shoulda', path: '../../..'"
steps %{And I run `bundle install --local`}
end

When /^I configure the application to use shoulda-context$/ do
append_to_gemfile "gem 'shoulda-context'"
steps %{And I run `bundle install --local`}
end

When /^I configure the application to use shoulda$/ do
append_to_gemfile "gem 'shoulda-matchers', '~> 1.0', :require => false"
append_to_gemfile "gem 'shoulda-context', '~> 1.0', :require => false"
append_to_gemfile "gem 'shoulda', :path => '../../..'"
steps %{And I run `bundle install --local`}
end

When /^I configure the application to use shoulda-matchers$/ do
append_to_gemfile "gem 'shoulda-matchers', '~> 1.0'"
steps %{And I run `bundle install --local`}
append_to 'test/test_helper.rb', <<-TEXT
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :minitest
with.library :rails
end
end
TEXT
end

When /^I configure a wildcard route$/ do
When 'I configure a wildcard route' do
steps %{
When I write to "config/routes.rb" with:
"""
Rails.application.routes.draw do
match ':controller(/:action(/:id(.:format)))'
get ':controller(/:action(/:id(.:format)))'
end
"""
}
end

module AppendHelpers
def append_to(path, contents)
in_current_dir do
File.open(path, "a") do |file|
file.puts
file.puts contents
end
end
end
When 'I successfully run the "test" task' do
steps %{
When I successfully run `bundle exec rake test TESTOPTS='-v' --trace`
}
end

def append_to_gemfile(contents)
append_to('Gemfile', contents)
Then /^the output should indicate that (\d+) tests were run successfully$/ do |number|
if rails_gte_4_1?
steps %{
Then the output should contain:
"""
#{number} runs, #{number} assertions, 0 failures, 0 errors
"""
}
else
steps %{
Then the output should contain:
"""
#{number} tests, #{number} assertions, 0 failures, 0 errors
"""
}
end
end

World(AppendHelpers)
27 changes: 27 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'aruba/cucumber'

PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
APP_NAME = 'testapp'.freeze

Before do
@aruba_timeout_seconds = 15

Expand All @@ -12,3 +15,27 @@
@announce_env = true
end
end

module AppendHelpers
def append_to(path, contents)
cd('.') 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
end

module RailsHelpers
def rails_version
Gem::Version.new(Bundler.definition.specs['rails'][0].version)
end
end

World(AppendHelpers)
World(RailsHelpers)
12 changes: 12 additions & 0 deletions gemfiles/4.2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "appraisal", "~> 2.1"
gem "rails", :git => "https://github.com/rails/rails.git", :branch => "4-2-stable"
gem "sqlite3"
gem "rspec", "~> 3.0"
gem "listen"
gem "sass-rails"
gem "shoulda-context"
gem "shoulda-matchers", "~> 3.0"
Loading

0 comments on commit b9353e2

Please sign in to comment.