shoulda-context 1.1.6 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Appraisals +32 -9
- data/gemfiles/minitest_4_x.gemfile +7 -0
- data/gemfiles/minitest_4_x.gemfile.lock +96 -0
- data/gemfiles/minitest_5_x.gemfile +7 -0
- data/gemfiles/minitest_5_x.gemfile.lock +102 -0
- data/gemfiles/rails_3_0.gemfile +8 -0
- data/gemfiles/{3.0.gemfile.lock → rails_3_0.gemfile.lock} +36 -34
- data/gemfiles/{3.2.gemfile → rails_3_1.gemfile} +2 -1
- data/gemfiles/{3.1.gemfile.lock → rails_3_1.gemfile.lock} +43 -41
- data/gemfiles/{3.1.gemfile → rails_3_2.gemfile} +2 -1
- data/gemfiles/{3.2.gemfile.lock → rails_3_2.gemfile.lock} +46 -45
- data/gemfiles/{4.0.gemfile → rails_4_0.gemfile} +3 -2
- data/gemfiles/rails_4_0.gemfile.lock +107 -0
- data/gemfiles/rails_4_1.gemfile +10 -0
- data/gemfiles/rails_4_1.gemfile.lock +119 -0
- data/gemfiles/{3.0.gemfile → test_unit.gemfile} +1 -1
- data/gemfiles/test_unit.gemfile.lock +95 -0
- data/lib/shoulda/context.rb +4 -17
- data/lib/shoulda/context/context.rb +9 -2
- data/lib/shoulda/context/test_framework_detection.rb +34 -0
- data/lib/shoulda/context/version.rb +1 -1
- data/test/shoulda/test_framework_detection_test.rb +154 -0
- data/test/test_helper.rb +9 -4
- metadata +21 -10
- data/gemfiles/4.0.gemfile.lock +0 -107
data/lib/shoulda/context.rb
CHANGED
@@ -1,19 +1,4 @@
|
|
1
|
-
|
2
|
-
# if present, load and set base_test_case
|
3
|
-
ActiveSupport::TestCase
|
4
|
-
if defined?([ActiveSupport::TestCase, MiniTest::Unit::TestCase]) &&
|
5
|
-
(ActiveSupport::TestCase.ancestors.include?(MiniTest::Unit::TestCase))
|
6
|
-
base_test_case = MiniTest::Unit::TestCase
|
7
|
-
end
|
8
|
-
rescue
|
9
|
-
end
|
10
|
-
|
11
|
-
# no base_test_case set, using Test:Unit:TestCase
|
12
|
-
unless base_test_case
|
13
|
-
require 'test/unit/testcase' unless defined?(Test::Unit::TestCase)
|
14
|
-
base_test_case = Test::Unit::TestCase
|
15
|
-
end
|
16
|
-
|
1
|
+
require 'shoulda/context/test_framework_detection'
|
17
2
|
require 'shoulda/context/version'
|
18
3
|
require 'shoulda/context/proc_extensions'
|
19
4
|
require 'shoulda/context/assertions'
|
@@ -30,4 +15,6 @@ module ShouldaContextLoadable
|
|
30
15
|
end
|
31
16
|
end
|
32
17
|
|
33
|
-
|
18
|
+
Shoulda::Context.test_framework_test_cases.each do |test_case|
|
19
|
+
test_case.class_eval { include ShouldaContextLoadable }
|
20
|
+
end
|
@@ -387,7 +387,7 @@ module Shoulda
|
|
387
387
|
end
|
388
388
|
|
389
389
|
def create_test_from_should_hash(should)
|
390
|
-
test_name = [
|
390
|
+
test_name = [test_name_prefix, full_name, "should", "#{should[:name]}. "].flatten.join(' ').to_sym
|
391
391
|
|
392
392
|
if test_methods[test_unit_class][test_name.to_s] then
|
393
393
|
raise DuplicateTestError, "'#{test_name}' is defined more than once."
|
@@ -470,10 +470,17 @@ module Shoulda
|
|
470
470
|
print_should_eventuallys
|
471
471
|
end
|
472
472
|
|
473
|
+
def test_name_prefix
|
474
|
+
if defined?(Minitest) || defined?(MiniTest)
|
475
|
+
'test_:'
|
476
|
+
else
|
477
|
+
'test:'
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
473
481
|
def method_missing(method, *args, &blk)
|
474
482
|
test_unit_class.send(method, *args, &blk)
|
475
483
|
end
|
476
|
-
|
477
484
|
end
|
478
485
|
end
|
479
486
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Context
|
3
|
+
module TestFrameworkDetection
|
4
|
+
def self.possible_test_frameworks
|
5
|
+
[
|
6
|
+
-> { ActiveSupport::TestCase },
|
7
|
+
-> { Minitest::Test },
|
8
|
+
-> { MiniTest::Unit::TestCase },
|
9
|
+
-> { Test::Unit::TestCase }
|
10
|
+
]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.resolve_framework(future_framework)
|
14
|
+
future_framework.call
|
15
|
+
rescue NameError
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.detected_test_framework_test_cases
|
20
|
+
possible_test_frameworks.
|
21
|
+
map { |future_framework| resolve_framework(future_framework) }.
|
22
|
+
compact
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.test_framework_test_cases
|
26
|
+
@_test_framework_test_case ||= detected_test_framework_test_cases
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.test_framework_test_cases
|
31
|
+
TestFrameworkDetection.test_framework_test_cases
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
class TestFrameworkDetectionTest < Test::Unit::TestCase
|
5
|
+
if CURRENT_APPRAISAL_NAME == 'rails_4_1'
|
6
|
+
should 'detect Minitest 5.x w/ Rails 4.1' do
|
7
|
+
assert_integration_with_rails_and 'Minitest::Test', 'Minitest::Unit::TestCase'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
if CURRENT_APPRAISAL_NAME == 'rails_4_0'
|
12
|
+
should 'detect ActiveSupport::TestCase and Minitest 4.x w/ Rails 4.0' do
|
13
|
+
assert_integration_with_rails_and 'MiniTest::Unit::TestCase'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if CURRENT_APPRAISAL_NAME == 'rails_3_2'
|
18
|
+
should 'detect ActiveSupport::TestCase and Test::Unit::TestCase w/ Rails 3.2' do
|
19
|
+
assert_integration_with_rails_and 'Test::Unit::TestCase'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if CURRENT_APPRAISAL_NAME == 'rails_3_1'
|
24
|
+
should 'detect ActiveSupport::TestCase and Test::Unit::TestCase w/ Rails 3.1' do
|
25
|
+
assert_integration_with_rails_and 'Test::Unit::TestCase'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if CURRENT_APPRAISAL_NAME == 'rails_3_0'
|
30
|
+
should 'detect ActiveSupport::TestCase and Test::Unit::TestCase w/ Rails 3.0' do
|
31
|
+
assert_integration_with_rails_and 'Test::Unit::TestCase'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
if CURRENT_APPRAISAL_NAME == 'minitest_5_x'
|
36
|
+
should 'detect Minitest 5.x when it is loaded standalone' do
|
37
|
+
assert_integration_with 'Minitest::Test', 'Minitest::Unit::TestCase',
|
38
|
+
setup: <<-RUBY
|
39
|
+
require 'minitest/autorun'
|
40
|
+
RUBY
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if CURRENT_APPRAISAL_NAME == 'minitest_4_x'
|
45
|
+
should 'detect Minitest 4.x when it is loaded standalone' do
|
46
|
+
assert_integration_with 'MiniTest::Unit::TestCase',
|
47
|
+
setup: <<-RUBY
|
48
|
+
require 'minitest/autorun'
|
49
|
+
RUBY
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
if CURRENT_APPRAISAL_NAME == 'test_unit'
|
54
|
+
should 'detect the test-unit gem when it is loaded standalone' do
|
55
|
+
assert_integration_with 'Test::Unit::TestCase',
|
56
|
+
setup: <<-RUBY
|
57
|
+
require 'test/unit'
|
58
|
+
RUBY
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def assert_integration_with(*test_cases)
|
63
|
+
assert_test_cases_are_detected(*test_cases)
|
64
|
+
assert_our_api_is_available_in_test_cases(*test_cases)
|
65
|
+
end
|
66
|
+
|
67
|
+
def assert_integration_with_rails_and(*test_cases)
|
68
|
+
test_cases = ['ActiveSupport::TestCase'] | test_cases
|
69
|
+
options = test_cases.last.is_a?(Hash) ? test_cases.pop : {}
|
70
|
+
options[:setup] = <<-RUBY
|
71
|
+
require 'rails/all'
|
72
|
+
require 'rails/test_help'
|
73
|
+
ActiveRecord::Base.establish_connection(
|
74
|
+
adapter: 'sqlite3',
|
75
|
+
database: ':memory:'
|
76
|
+
)
|
77
|
+
RUBY
|
78
|
+
args = test_cases + [options]
|
79
|
+
|
80
|
+
assert_integration_with(*args)
|
81
|
+
end
|
82
|
+
|
83
|
+
def assert_test_cases_are_detected(*expected_test_cases)
|
84
|
+
options = expected_test_cases.last.is_a?(Hash) ? expected_test_cases.pop : {}
|
85
|
+
setup = options[:setup] || ''
|
86
|
+
output = execute(file_that_detects_test_framework_test_cases([setup]))
|
87
|
+
actual_test_cases = output.split("\n").first.split(', ')
|
88
|
+
assert_equal expected_test_cases, actual_test_cases
|
89
|
+
end
|
90
|
+
|
91
|
+
def file_that_detects_test_framework_test_cases(mixins)
|
92
|
+
<<-RUBY
|
93
|
+
#{require_gems(mixins)}
|
94
|
+
require 'yaml'
|
95
|
+
test_cases = Shoulda::Context.test_framework_test_cases.map { |test_case| test_case.to_s }
|
96
|
+
puts test_cases.join(', ')
|
97
|
+
RUBY
|
98
|
+
end
|
99
|
+
|
100
|
+
def require_gems(mixins)
|
101
|
+
<<-RUBY
|
102
|
+
ENV['BUNDLE_GEMFILE'] = "#{PROJECT_DIR}/gemfiles/#{CURRENT_APPRAISAL_NAME}.gemfile"
|
103
|
+
require 'bundler'
|
104
|
+
Bundler.setup
|
105
|
+
#{mixins.join("\n")}
|
106
|
+
require 'shoulda-context'
|
107
|
+
RUBY
|
108
|
+
end
|
109
|
+
|
110
|
+
def assert_our_api_is_available_in_test_cases(*test_cases)
|
111
|
+
options = test_cases.last.is_a?(Hash) ? test_cases.pop : {}
|
112
|
+
setup = options[:setup] || ''
|
113
|
+
|
114
|
+
test_cases.each do |test_case|
|
115
|
+
output = execute(file_that_runs_a_test_within_test_case(test_case, [setup]))
|
116
|
+
assert_match /1 (tests|runs)/, output
|
117
|
+
assert_match /1 assertions/, output
|
118
|
+
assert_match /0 failures/, output
|
119
|
+
assert_match /0 errors/, output
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def file_that_runs_a_test_within_test_case(test_case, mixins)
|
124
|
+
<<-RUBY
|
125
|
+
#{require_gems(mixins)}
|
126
|
+
|
127
|
+
class FrameworkIntegrationTest < #{test_case}
|
128
|
+
context 'a context' do
|
129
|
+
should 'have a test' do
|
130
|
+
assert_equal true, true
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
RUBY
|
135
|
+
end
|
136
|
+
|
137
|
+
def execute(code)
|
138
|
+
tempfile = Tempfile.new('shoulda-context-test')
|
139
|
+
tempfile.write(code)
|
140
|
+
tempfile.close
|
141
|
+
|
142
|
+
if ENV['DEBUG']
|
143
|
+
puts 'Code:'
|
144
|
+
puts code
|
145
|
+
end
|
146
|
+
|
147
|
+
output = `RUBYOPT='' ruby #{tempfile.path} 2>&1`
|
148
|
+
if ENV['DEBUG']
|
149
|
+
puts 'Output:'
|
150
|
+
puts output
|
151
|
+
end
|
152
|
+
output
|
153
|
+
end
|
154
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -2,10 +2,15 @@ require 'fileutils'
|
|
2
2
|
require 'test/unit'
|
3
3
|
require 'mocha'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
if ENV['BUNDLE_GEMFILE'].to_s.empty?
|
6
|
+
raise "No Appraisal is specified. Please re-run your tests with BUNDLE_GEMFILE set."
|
7
|
+
end
|
8
|
+
|
9
|
+
PROJECT_DIR = File.expand_path('../..', __FILE__)
|
10
|
+
CURRENT_APPRAISAL_NAME = File.basename(ENV['BUNDLE_GEMFILE'], '.gemfile')
|
11
|
+
|
12
|
+
$LOAD_PATH << File.join(PROJECT_DIR, 'lib')
|
13
|
+
require 'shoulda/context'
|
8
14
|
|
9
15
|
Shoulda.autoload_macros File.join(File.dirname(__FILE__), 'fake_rails_root'),
|
10
16
|
File.join("vendor", "{plugins,gems}", "*")
|
11
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-context
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoughtbot, inc.
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date:
|
16
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: appraisal
|
@@ -102,14 +102,22 @@ files:
|
|
102
102
|
- README.md
|
103
103
|
- Rakefile
|
104
104
|
- bin/convert_to_should_syntax
|
105
|
-
- gemfiles/
|
106
|
-
- gemfiles/
|
107
|
-
- gemfiles/
|
108
|
-
- gemfiles/
|
109
|
-
- gemfiles/
|
110
|
-
- gemfiles/
|
111
|
-
- gemfiles/
|
112
|
-
- gemfiles/
|
105
|
+
- gemfiles/minitest_4_x.gemfile
|
106
|
+
- gemfiles/minitest_4_x.gemfile.lock
|
107
|
+
- gemfiles/minitest_5_x.gemfile
|
108
|
+
- gemfiles/minitest_5_x.gemfile.lock
|
109
|
+
- gemfiles/rails_3_0.gemfile
|
110
|
+
- gemfiles/rails_3_0.gemfile.lock
|
111
|
+
- gemfiles/rails_3_1.gemfile
|
112
|
+
- gemfiles/rails_3_1.gemfile.lock
|
113
|
+
- gemfiles/rails_3_2.gemfile
|
114
|
+
- gemfiles/rails_3_2.gemfile.lock
|
115
|
+
- gemfiles/rails_4_0.gemfile
|
116
|
+
- gemfiles/rails_4_0.gemfile.lock
|
117
|
+
- gemfiles/rails_4_1.gemfile
|
118
|
+
- gemfiles/rails_4_1.gemfile.lock
|
119
|
+
- gemfiles/test_unit.gemfile
|
120
|
+
- gemfiles/test_unit.gemfile.lock
|
113
121
|
- init.rb
|
114
122
|
- lib/shoulda-context.rb
|
115
123
|
- lib/shoulda/context.rb
|
@@ -120,6 +128,7 @@ files:
|
|
120
128
|
- lib/shoulda/context/tasks.rb
|
121
129
|
- lib/shoulda/context/tasks/list_tests.rake
|
122
130
|
- lib/shoulda/context/tasks/yaml_to_shoulda.rake
|
131
|
+
- lib/shoulda/context/test_framework_detection.rb
|
123
132
|
- lib/shoulda/context/version.rb
|
124
133
|
- rails/init.rb
|
125
134
|
- shoulda-context.gemspec
|
@@ -133,6 +142,7 @@ files:
|
|
133
142
|
- test/shoulda/convert_to_should_syntax_test.rb
|
134
143
|
- test/shoulda/helpers_test.rb
|
135
144
|
- test/shoulda/should_test.rb
|
145
|
+
- test/shoulda/test_framework_detection_test.rb
|
136
146
|
- test/test_helper.rb
|
137
147
|
homepage: http://thoughtbot.com/community/
|
138
148
|
licenses:
|
@@ -168,4 +178,5 @@ test_files:
|
|
168
178
|
- test/shoulda/convert_to_should_syntax_test.rb
|
169
179
|
- test/shoulda/helpers_test.rb
|
170
180
|
- test/shoulda/should_test.rb
|
181
|
+
- test/shoulda/test_framework_detection_test.rb
|
171
182
|
- test/test_helper.rb
|
data/gemfiles/4.0.gemfile.lock
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: /Users/rmcgeary/work/oss/shoulda-context
|
3
|
-
specs:
|
4
|
-
shoulda-context (1.1.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
actionmailer (4.0.0.rc1)
|
10
|
-
actionpack (= 4.0.0.rc1)
|
11
|
-
mail (~> 2.5.3)
|
12
|
-
actionpack (4.0.0.rc1)
|
13
|
-
activesupport (= 4.0.0.rc1)
|
14
|
-
builder (~> 3.1.0)
|
15
|
-
erubis (~> 2.7.0)
|
16
|
-
rack (~> 1.5.2)
|
17
|
-
rack-test (~> 0.6.2)
|
18
|
-
activemodel (4.0.0.rc1)
|
19
|
-
activesupport (= 4.0.0.rc1)
|
20
|
-
builder (~> 3.1.0)
|
21
|
-
activerecord (4.0.0.rc1)
|
22
|
-
activemodel (= 4.0.0.rc1)
|
23
|
-
activerecord-deprecated_finders (~> 1.0.2)
|
24
|
-
activesupport (= 4.0.0.rc1)
|
25
|
-
arel (~> 4.0.0)
|
26
|
-
activerecord-deprecated_finders (1.0.2)
|
27
|
-
activesupport (4.0.0.rc1)
|
28
|
-
i18n (~> 0.6, >= 0.6.4)
|
29
|
-
minitest (~> 4.2)
|
30
|
-
multi_json (~> 1.3)
|
31
|
-
thread_safe (~> 0.1)
|
32
|
-
tzinfo (~> 0.3.37)
|
33
|
-
appraisal (0.5.2)
|
34
|
-
bundler
|
35
|
-
rake
|
36
|
-
arel (4.0.0)
|
37
|
-
atomic (1.1.9)
|
38
|
-
builder (3.1.4)
|
39
|
-
erubis (2.7.0)
|
40
|
-
hike (1.2.2)
|
41
|
-
i18n (0.6.4)
|
42
|
-
jquery-rails (2.2.1)
|
43
|
-
railties (>= 3.0, < 5.0)
|
44
|
-
thor (>= 0.14, < 2.0)
|
45
|
-
mail (2.5.3)
|
46
|
-
i18n (>= 0.4.0)
|
47
|
-
mime-types (~> 1.16)
|
48
|
-
treetop (~> 1.4.8)
|
49
|
-
mime-types (1.23)
|
50
|
-
minitest (4.7.4)
|
51
|
-
mocha (0.9.12)
|
52
|
-
multi_json (1.7.3)
|
53
|
-
polyglot (0.3.3)
|
54
|
-
rack (1.5.2)
|
55
|
-
rack-test (0.6.2)
|
56
|
-
rack (>= 1.0)
|
57
|
-
rails (4.0.0.rc1)
|
58
|
-
actionmailer (= 4.0.0.rc1)
|
59
|
-
actionpack (= 4.0.0.rc1)
|
60
|
-
activerecord (= 4.0.0.rc1)
|
61
|
-
activesupport (= 4.0.0.rc1)
|
62
|
-
bundler (>= 1.3.0, < 2.0)
|
63
|
-
railties (= 4.0.0.rc1)
|
64
|
-
sprockets-rails (~> 2.0.0.rc4)
|
65
|
-
railties (4.0.0.rc1)
|
66
|
-
actionpack (= 4.0.0.rc1)
|
67
|
-
activesupport (= 4.0.0.rc1)
|
68
|
-
rake (>= 0.8.7)
|
69
|
-
thor (>= 0.18.1, < 2.0)
|
70
|
-
rake (10.0.4)
|
71
|
-
sass (3.2.9)
|
72
|
-
sass-rails (4.0.0.rc1)
|
73
|
-
railties (>= 4.0.0.beta, < 5.0)
|
74
|
-
sass (>= 3.1.10)
|
75
|
-
sprockets-rails (~> 2.0.0.rc0)
|
76
|
-
tilt (~> 1.3)
|
77
|
-
sprockets (2.9.3)
|
78
|
-
hike (~> 1.2)
|
79
|
-
multi_json (~> 1.0)
|
80
|
-
rack (~> 1.0)
|
81
|
-
tilt (~> 1.1, != 1.3.0)
|
82
|
-
sprockets-rails (2.0.0.rc4)
|
83
|
-
actionpack (>= 3.0)
|
84
|
-
activesupport (>= 3.0)
|
85
|
-
sprockets (~> 2.8)
|
86
|
-
test-unit (2.1.2)
|
87
|
-
thor (0.18.1)
|
88
|
-
thread_safe (0.1.0)
|
89
|
-
atomic
|
90
|
-
tilt (1.4.1)
|
91
|
-
treetop (1.4.12)
|
92
|
-
polyglot
|
93
|
-
polyglot (>= 0.3.1)
|
94
|
-
tzinfo (0.3.37)
|
95
|
-
|
96
|
-
PLATFORMS
|
97
|
-
ruby
|
98
|
-
|
99
|
-
DEPENDENCIES
|
100
|
-
appraisal (~> 0.5)
|
101
|
-
jquery-rails
|
102
|
-
mocha (~> 0.9.10)
|
103
|
-
rails (= 4.0.0.rc1)
|
104
|
-
rake
|
105
|
-
sass-rails (= 4.0.0.rc1)
|
106
|
-
shoulda-context!
|
107
|
-
test-unit (~> 2.1.0)
|