-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent leaking view contexts between tests
- Loading branch information
Showing
17 changed files
with
177 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
require 'rspec/core/rake_task' | ||
require 'rake/testtask' | ||
require 'rspec/core/rake_task' | ||
|
||
Rake::Task[:test].clear | ||
Rake::TestTask.new :test do |t| | ||
t.libs << "test" | ||
t.pattern = "test/**/*_test.rb" | ||
end | ||
|
||
RSpec::Core::RakeTask.new :rspec | ||
RSpec::Core::RakeTask.new :spec | ||
|
||
RSpec::Core::RakeTask.new :fast_spec do |t| | ||
t.pattern = "fast_spec/**/*_spec.rb" | ||
end | ||
|
||
Rake::TestTask.new :mini_test do |t| | ||
t.test_files = ["mini_test/mini_test_integration_test.rb"] | ||
end | ||
|
||
task :default => [:rspec, :mini_test, :fast_spec] | ||
task :default => [:test, :spec, :fast_spec] |
6 changes: 1 addition & 5 deletions
6
...spec/decorators/rspec_integration_spec.rb → spec/dummy/spec/decorators/helpers_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'spec_helper' | ||
|
||
describe "A spec in this folder" do | ||
it "is a decorator spec" do | ||
expect(example.metadata[:type]).to be :decorator | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'spec_helper' | ||
|
||
def it_does_not_leak_view_context | ||
2.times do | ||
it "has an independent view context" do | ||
expect(Draper::ViewContext.current).not_to be :leaked | ||
Draper::ViewContext.current = :leaked | ||
end | ||
end | ||
end | ||
|
||
describe "A decorator spec", type: :decorator do | ||
it_does_not_leak_view_context | ||
end | ||
|
||
describe "A controller spec", type: :controller do | ||
it_does_not_leak_view_context | ||
end | ||
|
||
describe "A mailer spec", type: :mailer do | ||
it_does_not_leak_view_context | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'minitest_helper' | ||
|
||
describe "A decorator test" do | ||
it "can access helpers through `helper`" do | ||
assert_equal "<p>Help!</p>", helper.content_tag(:p, "Help!") | ||
end | ||
|
||
it "can access helpers through `helpers`" do | ||
assert_equal "<p>Help!</p>", helpers.content_tag(:p, "Help!") | ||
end | ||
|
||
it "can access helpers through `h`" do | ||
assert_equal "<p>Help!</p>", h.content_tag(:p, "Help!") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'minitest_helper' | ||
|
||
def it_does_not_leak_view_context | ||
2.times do | ||
it "has an independent view context" do | ||
refute_equal :leaked, Draper::ViewContext.current | ||
Draper::ViewContext.current = :leaked | ||
end | ||
end | ||
end | ||
|
||
describe "A decorator test" do | ||
it_does_not_leak_view_context | ||
end | ||
|
||
describe "A controller test" do | ||
tests Class.new(ActionController::Base) | ||
|
||
it_does_not_leak_view_context | ||
end | ||
|
||
describe "A mailer test" do | ||
it_does_not_leak_view_context | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'test_helper' | ||
|
||
class HelpersTest < Draper::TestCase | ||
def test_access_helpers_through_helper | ||
assert_equal "<p>Help!</p>", helper.content_tag(:p, "Help!") | ||
end | ||
|
||
def test_access_helpers_through_helpers | ||
assert_equal "<p>Help!</p>", helpers.content_tag(:p, "Help!") | ||
end | ||
|
||
def test_access_helpers_through_h | ||
assert_equal "<p>Help!</p>", h.content_tag(:p, "Help!") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'test_helper' | ||
|
||
def it_does_not_leak_view_context | ||
2.times do |n| | ||
define_method("test_has_independent_view_context_#{n}") do | ||
refute_equal :leaked, Draper::ViewContext.current | ||
Draper::ViewContext.current = :leaked | ||
end | ||
end | ||
end | ||
|
||
class DecoratorTest < Draper::TestCase | ||
it_does_not_leak_view_context | ||
end | ||
|
||
class ControllerTest < ActionController::TestCase | ||
tests Class.new(ActionController::Base) | ||
|
||
it_does_not_leak_view_context | ||
end | ||
|
||
class MailerTest < ActionMailer::TestCase | ||
it_does_not_leak_view_context | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ENV['RAILS_ENV'] ||= 'test' | ||
require File.expand_path('../../config/environment', __FILE__) | ||
require 'minitest/autorun' | ||
require 'minitest/rails' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ENV['RAILS_ENV'] ||= 'test' | ||
require File.expand_path('../../config/environment', __FILE__) | ||
require 'rails/test_help' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters