shoulda 3.6.0 → 4.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +181 -2
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +24 -9
  6. data/Appraisals +108 -10
  7. data/Gemfile +9 -5
  8. data/README.md +24 -17
  9. data/Rakefile +18 -13
  10. data/gemfiles/rails_4_2.gemfile +31 -0
  11. data/gemfiles/rails_4_2.gemfile.lock +240 -0
  12. data/gemfiles/rails_5_0.gemfile +29 -0
  13. data/gemfiles/rails_5_0.gemfile.lock +232 -0
  14. data/gemfiles/rails_5_1.gemfile +30 -0
  15. data/gemfiles/rails_5_1.gemfile.lock +249 -0
  16. data/gemfiles/rails_5_2.gemfile +32 -0
  17. data/gemfiles/rails_5_2.gemfile.lock +268 -0
  18. data/gemfiles/rails_6_0.gemfile +34 -0
  19. data/gemfiles/rails_6_0.gemfile.lock +285 -0
  20. data/lib/shoulda/version.rb +1 -1
  21. data/script/install_gems_in_all_appraisals +16 -0
  22. data/script/run_all_tests +16 -0
  23. data/script/supported_ruby_versions +7 -0
  24. data/script/update_gem_in_all_appraisals +17 -0
  25. data/script/update_gems_in_all_appraisals +16 -0
  26. data/shoulda.gemspec +3 -3
  27. data/test/acceptance/integrates_with_rails_test.rb +580 -0
  28. data/test/acceptance_test_helper.rb +32 -6
  29. data/test/support/acceptance/add_shoulda_to_project.rb +13 -18
  30. data/test/support/acceptance/matchers/have_output.rb +2 -0
  31. data/test/support/acceptance/matchers/indicate_that_tests_were_run.rb +109 -0
  32. data/test/support/acceptance/rails_application_with_shoulda.rb +47 -0
  33. data/test/support/{tests/current_bundle.rb → current_bundle.rb} +4 -4
  34. data/test/support/snowglobe.rb +5 -0
  35. data/test/test_helper.rb +9 -4
  36. metadata +37 -65
  37. data/.hound/ruby.yml +0 -1042
  38. data/gemfiles/4.2.gemfile +0 -17
  39. data/gemfiles/4.2.gemfile.lock +0 -174
  40. data/gemfiles/5.0.gemfile +0 -17
  41. data/gemfiles/5.0.gemfile.lock +0 -179
  42. data/test/acceptance/rails_integration_test.rb +0 -76
  43. data/test/report_warnings.rb +0 -7
  44. data/test/support/acceptance/helpers.rb +0 -19
  45. data/test/support/acceptance/helpers/active_model_helpers.rb +0 -11
  46. data/test/support/acceptance/helpers/base_helpers.rb +0 -14
  47. data/test/support/acceptance/helpers/command_helpers.rb +0 -54
  48. data/test/support/acceptance/helpers/file_helpers.rb +0 -19
  49. data/test/support/acceptance/helpers/gem_helpers.rb +0 -31
  50. data/test/support/acceptance/helpers/step_helpers.rb +0 -69
  51. data/test/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +0 -54
  52. data/test/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +0 -75
  53. data/test/support/tests/bundle.rb +0 -94
  54. data/test/support/tests/command_runner.rb +0 -230
  55. data/test/support/tests/filesystem.rb +0 -100
  56. data/test/support/tests/version.rb +0 -45
  57. data/test/warnings_spy.rb +0 -62
  58. data/test/warnings_spy/filesystem.rb +0 -45
  59. data/test/warnings_spy/partitioner.rb +0 -36
  60. data/test/warnings_spy/reader.rb +0 -53
  61. data/test/warnings_spy/reporter.rb +0 -88
@@ -1,4 +1,4 @@
1
- require_relative 'support/tests/current_bundle'
1
+ require_relative 'support/current_bundle'
2
2
 
3
3
  Tests::CurrentBundle.instance.assert_appraisal!
4
4
 
@@ -6,12 +6,38 @@ Tests::CurrentBundle.instance.assert_appraisal!
6
6
 
7
7
  require 'test_helper'
8
8
 
9
- acceptance_test_support_files =
10
- Pathname.new('../support/acceptance/**/*.rb').expand_path(__FILE__)
11
-
12
- Dir.glob(acceptance_test_support_files).sort.each { |file| require file }
9
+ require_relative 'support/acceptance/rails_application_with_shoulda'
10
+ require_relative 'support/acceptance/matchers/have_output'
11
+ require_relative 'support/acceptance/matchers/indicate_that_tests_were_run'
13
12
 
14
13
  class AcceptanceTest < Minitest::Test
15
- include AcceptanceTests::Helpers
16
14
  include AcceptanceTests::Matchers
15
+
16
+ private
17
+
18
+ def app
19
+ @app ||= AcceptanceTests::RailsApplicationWithShoulda.new
20
+ end
21
+ end
22
+
23
+ begin
24
+ require 'rails/test_unit/reporter'
25
+
26
+ # Patch Rails' reporter for Minitest so that it looks for the test
27
+ # correctly under Minitest 5.11
28
+ # See: <https://github.com/rails/rails/pull/31624>
29
+ Rails::TestUnitReporter.class_eval do
30
+ def format_rerun_snippet(result)
31
+ location, line =
32
+ if result.respond_to?(:source_location)
33
+ result.source_location
34
+ else
35
+ result.method(result.name).source_location
36
+ end
37
+
38
+ "#{executable} #{relative_path_for(location)}:#{line}"
39
+ end
40
+ end
41
+ rescue LoadError
42
+ # Okay, rails/test_unit/reporter isn't a thing, no big deal
17
43
  end
@@ -1,33 +1,28 @@
1
- require_relative 'helpers/base_helpers'
2
- require_relative 'helpers/gem_helpers'
3
-
4
1
  module AcceptanceTests
5
2
  class AddShouldaToProject
6
- def self.call(options)
7
- new(options).call
8
- end
3
+ ROOT_DIRECTORY = Pathname.new('../../..').expand_path(__FILE__)
9
4
 
10
- include BaseHelpers
11
- include GemHelpers
5
+ def self.call(app, options)
6
+ new(app, options).call
7
+ end
12
8
 
13
- def initialize(options)
9
+ def initialize(app, options)
10
+ @app = app
14
11
  @options = options
15
12
  end
16
13
 
17
14
  def call
18
- add_gem 'shoulda', gem_options
15
+ app.add_gem 'shoulda', gem_options
19
16
 
20
17
  unless options[:with_configuration] === false
21
18
  add_configuration_block_to_test_helper
22
19
  end
23
20
  end
24
21
 
25
- protected
26
-
27
- attr_reader :options
28
-
29
22
  private
30
23
 
24
+ attr_reader :app, :options
25
+
31
26
  def test_framework
32
27
  options[:test_framework]
33
28
  end
@@ -37,7 +32,7 @@ module AcceptanceTests
37
32
  end
38
33
 
39
34
  def gem_options
40
- gem_options = { path: fs.root_directory }
35
+ gem_options = { path: ROOT_DIRECTORY }
41
36
 
42
37
  if options[:manually]
43
38
  gem_options[:require] = false
@@ -47,20 +42,20 @@ module AcceptanceTests
47
42
  end
48
43
 
49
44
  def add_configuration_block_to_test_helper
50
- content = <<-EOT
45
+ content = <<-CONTENT
51
46
  Shoulda::Matchers.configure do |config|
52
47
  config.integrate do |with|
53
48
  #{test_framework_config}
54
49
  #{library_config}
55
50
  end
56
51
  end
57
- EOT
52
+ CONTENT
58
53
 
59
54
  if options[:manually]
60
55
  content = "require 'shoulda'\n#{content}"
61
56
  end
62
57
 
63
- fs.append_to_file('test/test_helper.rb', content)
58
+ app.append_to_file('test/test_helper.rb', content)
64
59
  end
65
60
 
66
61
  def test_framework_config
@@ -1,8 +1,10 @@
1
1
  module AcceptanceTests
2
2
  module Matchers
3
+ # rubocop:disable Naming/PredicateName
3
4
  def have_output(output)
4
5
  HaveOutputMatcher.new(output)
5
6
  end
7
+ # rubocop:enable Naming/PredicateName
6
8
 
7
9
  class HaveOutputMatcher
8
10
  def initialize(output)
@@ -0,0 +1,109 @@
1
+ require_relative '../helpers/array_helpers'
2
+ require_relative '../helpers/pluralization_helpers'
3
+
4
+ module AcceptanceTests
5
+ module Matchers
6
+ def indicate_that_tests_were_run(series)
7
+ IndicateThatTestsWereRunMatcher.new(series)
8
+ end
9
+
10
+ class IndicateThatTestsWereRunMatcher
11
+ include ArrayHelpers
12
+ include PluralizationHelpers
13
+
14
+ def initialize(expected_numbers)
15
+ @expected_numbers = expected_numbers
16
+ end
17
+
18
+ def matches?(runner)
19
+ @runner = runner
20
+ Set.new(expected_numbers).subset?(Set.new(actual_numbers))
21
+ end
22
+
23
+ def failure_message
24
+ "Expected output to indicate that #{some_tests_were_run}.\n" +
25
+ "#{formatted_expected_numbers}\n" +
26
+ "#{formatted_actual_numbers}\n\n" +
27
+ "Output:\n\n" +
28
+ actual_output
29
+ end
30
+
31
+ protected
32
+
33
+ attr_reader :expected_numbers, :runner
34
+
35
+ private
36
+
37
+ def some_tests_were_run
38
+ if some_tests_were_run_clauses.size > 1
39
+ "#{to_sentence(some_tests_were_run_clauses)} were run"
40
+ else
41
+ "#{some_tests_were_run_clauses} was run"
42
+ end
43
+ end
44
+
45
+ def some_tests_were_run_clauses
46
+ expected_numbers.map do |type, number|
47
+ if number == 1
48
+ "#{number} #{type.to_s.chop}"
49
+ else
50
+ "#{number} #{type}"
51
+ end
52
+ end
53
+ end
54
+
55
+ def formatted_expected_numbers
56
+ "Expected numbers: #{format_hash(expected_numbers)}"
57
+ end
58
+
59
+ def formatted_actual_numbers
60
+ report_line = find_report_line_in(actual_output)
61
+
62
+ if report_line
63
+ "Actual numbers: #{report_line.inspect}"
64
+ else
65
+ 'Actual numbers: (n/a)'
66
+ end
67
+ end
68
+
69
+ def actual_numbers
70
+ numbers = parse(
71
+ actual_output,
72
+ [:tests, :assertions, :failures, :errors, :skips],
73
+ )
74
+ numbers || {}
75
+ end
76
+
77
+ def actual_output
78
+ runner.output
79
+ end
80
+
81
+ def parse(text, pieces)
82
+ report_line = find_report_line_in(text)
83
+
84
+ if report_line
85
+ pieces.inject({}) do |hash, piece|
86
+ number = report_line.match(/(\d+) #{piece}/)[1].to_i
87
+ hash.merge(piece => number)
88
+ end
89
+ end
90
+ end
91
+
92
+ def find_report_line_in(text)
93
+ lines = text.split(/\n/)
94
+
95
+ index_of_line_with_time = lines.find_index do |line|
96
+ line =~ /\AFinished in \d\.\d+s\Z/
97
+ end
98
+
99
+ if index_of_line_with_time
100
+ lines[index_of_line_with_time + 1]
101
+ end
102
+ end
103
+
104
+ def format_hash(hash)
105
+ '{' + hash.map { |k, v| "#{k}: #{v.inspect}" }.join(', ') + '}'
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,47 @@
1
+ require_relative 'add_shoulda_to_project'
2
+ require_relative '../snowglobe'
3
+
4
+ module AcceptanceTests
5
+ class RailsApplicationWithShoulda < Snowglobe::RailsApplication
6
+ def create
7
+ super
8
+
9
+ bundle.updating do
10
+ bundle.add_gem 'minitest-reporters'
11
+ AddShouldaToProject.call(
12
+ self,
13
+ test_framework: :minitest,
14
+ libraries: [:rails],
15
+ )
16
+ end
17
+
18
+ fs.append_to_file 'test/test_helper.rb', <<-FILE
19
+ require 'minitest/autorun'
20
+ require 'minitest/reporters'
21
+
22
+ Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
23
+
24
+ begin
25
+ require "rails/test_unit/reporter"
26
+
27
+ # Patch Rails' reporter for Minitest so that it looks for the test
28
+ # correctly under Minitest 5.11
29
+ # See: <https://github.com/rails/rails/pull/31624>
30
+ Rails::TestUnitReporter.class_eval do
31
+ def format_rerun_snippet(result)
32
+ location, line = if result.respond_to?(:source_location)
33
+ result.source_location
34
+ else
35
+ result.method(result.name).source_location
36
+ end
37
+
38
+ "\#{executable} \#{relative_path_for(location)}:\#{line}"
39
+ end
40
+ end
41
+ rescue LoadError
42
+ # Okay, rails/test_unit/reporter isn't a thing, no big deal
43
+ end
44
+ FILE
45
+ end
46
+ end
47
+ end
@@ -9,13 +9,13 @@ module Tests
9
9
 
10
10
  def assert_appraisal!
11
11
  unless appraisal_in_use?
12
- message = <<EOT
12
+ message = <<MSG
13
13
 
14
14
 
15
15
  Please run tests starting with `appraisal <appraisal_name>`.
16
16
  Possible appraisals are: #{available_appraisals}
17
17
 
18
- EOT
18
+ MSG
19
19
  raise AppraisalNotSpecified, message
20
20
  end
21
21
  end
@@ -29,7 +29,7 @@ EOT
29
29
  end
30
30
 
31
31
  def latest_appraisal
32
- available_appraisals.sort.last
32
+ available_appraisals.max
33
33
  end
34
34
 
35
35
  private
@@ -55,7 +55,7 @@ EOT
55
55
  end
56
56
 
57
57
  def root
58
- Pathname.new('../../../..').expand_path(__FILE__)
58
+ Pathname.new('../../..').expand_path(__FILE__)
59
59
  end
60
60
  end
61
61
  end
@@ -0,0 +1,5 @@
1
+ require 'snowglobe'
2
+
3
+ Snowglobe.configure do |config|
4
+ config.project_name = 'shoulda'
5
+ end
@@ -1,14 +1,19 @@
1
- PROJECT_ROOT = Pathname.new('../..').expand_path(__FILE__).freeze
2
- $LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
3
-
1
+ require 'bundler/setup'
4
2
  require 'pry'
5
3
  require 'pry-byebug'
6
4
  require 'minitest/autorun'
7
5
  require 'minitest/reporters'
8
- require 'shoulda'
6
+ require 'warnings_logger'
7
+
8
+ require_relative '../lib/shoulda'
9
9
 
10
10
  Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
11
11
 
12
+ WarningsLogger::Spy.call(
13
+ project_name: 'shoulda',
14
+ project_directory: Pathname.new('../..').expand_path(__FILE__),
15
+ )
16
+
12
17
  Shoulda::Matchers.configure do |config|
13
18
  config.integrate do |with|
14
19
  with.test_framework :minitest
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoulda
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 4.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tammer Saleh
@@ -12,42 +12,36 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2018-07-13 00:00:00.000000000 Z
15
+ date: 2019-12-18 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: shoulda-context
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - "~>"
22
- - !ruby/object:Gem::Version
23
- version: '1.0'
24
- - - ">="
21
+ - - '='
25
22
  - !ruby/object:Gem::Version
26
- version: 1.0.1
23
+ version: 2.0.0.rc2
27
24
  type: :runtime
28
25
  prerelease: false
29
26
  version_requirements: !ruby/object:Gem::Requirement
30
27
  requirements:
31
- - - "~>"
28
+ - - '='
32
29
  - !ruby/object:Gem::Version
33
- version: '1.0'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 1.0.1
30
+ version: 2.0.0.rc2
37
31
  - !ruby/object:Gem::Dependency
38
32
  name: shoulda-matchers
39
33
  requirement: !ruby/object:Gem::Requirement
40
34
  requirements:
41
35
  - - "~>"
42
36
  - !ruby/object:Gem::Version
43
- version: '3.0'
37
+ version: '4.0'
44
38
  type: :runtime
45
39
  prerelease: false
46
40
  version_requirements: !ruby/object:Gem::Requirement
47
41
  requirements:
48
42
  - - "~>"
49
43
  - !ruby/object:Gem::Version
50
- version: '3.0'
44
+ version: '4.0'
51
45
  description: Making tests easy on the fingers and eyes
52
46
  email: support@thoughtbot.com
53
47
  executables: []
@@ -57,8 +51,8 @@ files:
57
51
  - ".autotest"
58
52
  - ".gitignore"
59
53
  - ".hound.yml"
60
- - ".hound/ruby.yml"
61
54
  - ".rubocop.yml"
55
+ - ".ruby-version"
62
56
  - ".travis.yml"
63
57
  - Appraisals
64
58
  - CONTRIBUTING.md
@@ -66,40 +60,35 @@ files:
66
60
  - MIT-LICENSE
67
61
  - README.md
68
62
  - Rakefile
69
- - gemfiles/4.2.gemfile
70
- - gemfiles/4.2.gemfile.lock
71
- - gemfiles/5.0.gemfile
72
- - gemfiles/5.0.gemfile.lock
63
+ - gemfiles/rails_4_2.gemfile
64
+ - gemfiles/rails_4_2.gemfile.lock
65
+ - gemfiles/rails_5_0.gemfile
66
+ - gemfiles/rails_5_0.gemfile.lock
67
+ - gemfiles/rails_5_1.gemfile
68
+ - gemfiles/rails_5_1.gemfile.lock
69
+ - gemfiles/rails_5_2.gemfile
70
+ - gemfiles/rails_5_2.gemfile.lock
71
+ - gemfiles/rails_6_0.gemfile
72
+ - gemfiles/rails_6_0.gemfile.lock
73
73
  - lib/shoulda.rb
74
74
  - lib/shoulda/version.rb
75
+ - script/install_gems_in_all_appraisals
76
+ - script/run_all_tests
77
+ - script/supported_ruby_versions
78
+ - script/update_gem_in_all_appraisals
79
+ - script/update_gems_in_all_appraisals
75
80
  - shoulda.gemspec
76
- - test/acceptance/rails_integration_test.rb
81
+ - test/acceptance/integrates_with_rails_test.rb
77
82
  - test/acceptance_test_helper.rb
78
- - test/report_warnings.rb
79
83
  - test/support/acceptance/add_shoulda_to_project.rb
80
- - test/support/acceptance/helpers.rb
81
- - test/support/acceptance/helpers/active_model_helpers.rb
82
84
  - test/support/acceptance/helpers/array_helpers.rb
83
- - test/support/acceptance/helpers/base_helpers.rb
84
- - test/support/acceptance/helpers/command_helpers.rb
85
- - test/support/acceptance/helpers/file_helpers.rb
86
- - test/support/acceptance/helpers/gem_helpers.rb
87
85
  - test/support/acceptance/helpers/pluralization_helpers.rb
88
- - test/support/acceptance/helpers/step_helpers.rb
89
86
  - test/support/acceptance/matchers/have_output.rb
90
- - test/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb
91
- - test/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb
92
- - test/support/tests/bundle.rb
93
- - test/support/tests/command_runner.rb
94
- - test/support/tests/current_bundle.rb
95
- - test/support/tests/filesystem.rb
96
- - test/support/tests/version.rb
87
+ - test/support/acceptance/matchers/indicate_that_tests_were_run.rb
88
+ - test/support/acceptance/rails_application_with_shoulda.rb
89
+ - test/support/current_bundle.rb
90
+ - test/support/snowglobe.rb
97
91
  - test/test_helper.rb
98
- - test/warnings_spy.rb
99
- - test/warnings_spy/filesystem.rb
100
- - test/warnings_spy/partitioner.rb
101
- - test/warnings_spy/reader.rb
102
- - test/warnings_spy/reporter.rb
103
92
  homepage: https://github.com/thoughtbot/shoulda
104
93
  licenses:
105
94
  - MIT
@@ -115,40 +104,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
104
  version: '0'
116
105
  required_rubygems_version: !ruby/object:Gem::Requirement
117
106
  requirements:
118
- - - ">="
107
+ - - ">"
119
108
  - !ruby/object:Gem::Version
120
- version: '0'
109
+ version: 1.3.1
121
110
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 2.7.6
111
+ rubygems_version: 3.0.6
124
112
  signing_key:
125
113
  specification_version: 4
126
114
  summary: Making tests easy on the fingers and eyes
127
115
  test_files:
128
- - test/acceptance/rails_integration_test.rb
116
+ - test/acceptance/integrates_with_rails_test.rb
129
117
  - test/acceptance_test_helper.rb
130
- - test/report_warnings.rb
131
118
  - test/support/acceptance/add_shoulda_to_project.rb
132
- - test/support/acceptance/helpers.rb
133
- - test/support/acceptance/helpers/active_model_helpers.rb
134
119
  - test/support/acceptance/helpers/array_helpers.rb
135
- - test/support/acceptance/helpers/base_helpers.rb
136
- - test/support/acceptance/helpers/command_helpers.rb
137
- - test/support/acceptance/helpers/file_helpers.rb
138
- - test/support/acceptance/helpers/gem_helpers.rb
139
120
  - test/support/acceptance/helpers/pluralization_helpers.rb
140
- - test/support/acceptance/helpers/step_helpers.rb
141
121
  - test/support/acceptance/matchers/have_output.rb
142
- - test/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb
143
- - test/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb
144
- - test/support/tests/bundle.rb
145
- - test/support/tests/command_runner.rb
146
- - test/support/tests/current_bundle.rb
147
- - test/support/tests/filesystem.rb
148
- - test/support/tests/version.rb
122
+ - test/support/acceptance/matchers/indicate_that_tests_were_run.rb
123
+ - test/support/acceptance/rails_application_with_shoulda.rb
124
+ - test/support/current_bundle.rb
125
+ - test/support/snowglobe.rb
149
126
  - test/test_helper.rb
150
- - test/warnings_spy.rb
151
- - test/warnings_spy/filesystem.rb
152
- - test/warnings_spy/partitioner.rb
153
- - test/warnings_spy/reader.rb
154
- - test/warnings_spy/reporter.rb