Skip to content

Commit

Permalink
Test against Rails 5 release instead of Beta
Browse files Browse the repository at this point in the history
Rails 5 raises a `ActionView::Template::Error` instead of
`ActionView::MissingTemplate` when a partial is missing now. This adds a
shim to handle the difference in testing across different versions of
Rails.
  • Loading branch information
Damian Galarza committed Dec 5, 2016
1 parent cbab60f commit 3ed17de
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 44 deletions.
3 changes: 1 addition & 2 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ rails_versions.each do |rails_version|
end

appraise "rails50" do
gem "rails", "~> 5.0.0.beta3"
gem "rspec-rails", "3.5.0.beta1"
gem "rails", "~> 5.0.0"
gem "rails-controller-testing"
end
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ source "https://rubygems.org"
gemspec

gem "appraisal"
gem "rspec-rails", "~> 3.2"
gem "rspec-rails", "~> 3.5.0"
42 changes: 22 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ GEM
loofah (2.0.3)
nokogiri (>= 1.5.9)
method_source (0.8.2)
mini_portile2 (2.0.0)
mini_portile2 (2.1.0)
minitest (5.8.4)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
pkg-config (1.1.7)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand All @@ -63,23 +65,23 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.5.0)
rspec-core (3.4.3)
rspec-support (~> 3.4.0)
rspec-expectations (3.4.0)
rspec-core (3.5.1)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-mocks (3.4.1)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.4.0)
rspec-rails (3.4.2)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rspec-support (~> 3.5.0)
rspec-rails (3.5.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
slop (3.6.0)
thor (0.19.1)
thread_safe (0.3.5)
Expand All @@ -94,7 +96,7 @@ DEPENDENCIES
appraisal
high_voltage!
pry
rspec-rails (~> 3.2)
rspec-rails (~> 3.5.0)

BUNDLED WITH
1.11.2
1.12.5
2 changes: 1 addition & 1 deletion gemfiles/rails4.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "https://rubygems.org"

gem "appraisal"
gem "rspec-rails", "~> 3.2"
gem "rspec-rails", "~> 3.5.0"
gem "rails", "~> 4.0.0"

gemspec :path => "../"
2 changes: 1 addition & 1 deletion gemfiles/rails4.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "https://rubygems.org"

gem "appraisal"
gem "rspec-rails", "~> 3.2"
gem "rspec-rails", "~> 3.5.0"
gem "rails", "~> 4.1.0"

gemspec :path => "../"
2 changes: 1 addition & 1 deletion gemfiles/rails4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source "https://rubygems.org"

gem "appraisal"
gem "rspec-rails", "~> 3.2"
gem "rspec-rails", "~> 3.5.0"
gem "rails", "~> 4.2.0"

gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/rails50.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
source "https://rubygems.org"

gem "appraisal"
gem "rspec-rails", "3.5.0.beta1"
gem "rails", "~> 5.0.0.beta3"
gem "rspec-rails", "~> 3.5.0"
gem "rails", "~> 5.0.0"
gem "rails-controller-testing"

gemspec :path => "../"
4 changes: 2 additions & 2 deletions spec/controllers/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

it "raises a missing template error for valid page with invalid partial" do
expect { get :show, id: "exists_but_references_nonexistent_partial" }.
to raise_error(ActionView::MissingTemplate)
to raise_error(missing_template_error)
end
end

Expand Down Expand Up @@ -107,7 +107,7 @@
id = "also_exists_but_references_nonexistent_partial"

expect { get :show, id: id }.
to raise_error(ActionView::MissingTemplate)
to raise_error(missing_template_error)
end
end
end
28 changes: 14 additions & 14 deletions spec/controllers/subclassed_pages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
require 'spec_helper'
require "spec_helper"

describe SubclassedPagesController do
render_views

describe 'on GET to /subclassed_pages/also_exists' do
before { get :show, :id => 'also_exists' }
describe "on GET to /subclassed_pages/also_exists" do
before { get :show, id: "also_exists" }

it 'responds with success and render template' do
it "responds with success and render template" do
expect(response).to be_succes
expect(response).to render_template('also_exists')
expect(response).to render_template("also_exists")
end

it 'uses the custom configured layout' do
expect(response).not_to render_template('layouts/application')
expect(response).to render_template('layouts/alternate')
it "uses the custom configured layout" do
expect(response).not_to render_template("layouts/application")
expect(response).to render_template("layouts/alternate")
end
end

it 'raises a routing error for an invalid page' do
expect { get :show, id: 'invalid' }
.to raise_error(ActionController::RoutingError)
expect { get :show, id: "invalid" }.
to raise_error(ActionController::RoutingError)
end

it 'raises a routing error for a page in another directory' do
expect { get :show, id: '../other/wrong' }
.to raise_error(ActionController::RoutingError)
expect { get :show, id: "../other/wrong" }.
to raise_error(ActionController::RoutingError)
end

it 'raises a missing template error for valid page with invalid partial' do
expect { get :show, id: 'also_exists_but_references_nonexistent_partial' }
.to raise_error(ActionView::MissingTemplate)
expect { get :show, id: "also_exists_but_references_nonexistent_partial" }.
to raise_error(missing_template_error)
end
end
13 changes: 13 additions & 0 deletions spec/support/missing_template_error_shim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module MissingTemplateErrorShim
def missing_template_error
if Rails::VERSION::MAJOR >= 5
ActionView::Template::Error
else
ActionView::MissingTemplate
end
end
end

RSpec.configure do |config|
config.include MissingTemplateErrorShim, type: :controller
end

0 comments on commit 3ed17de

Please sign in to comment.