shoulda 3.5.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +7 -7
  3. data/.hound.yml +3 -0
  4. data/.hound/ruby.yml +1042 -0
  5. data/.rubocop.yml +13 -0
  6. data/.travis.yml +11 -7
  7. data/Appraisals +13 -10
  8. data/CONTRIBUTING.md +6 -1
  9. data/Gemfile +8 -1
  10. data/README.md +58 -73
  11. data/Rakefile +21 -12
  12. data/gemfiles/4.2.gemfile +17 -0
  13. data/gemfiles/4.2.gemfile.lock +174 -0
  14. data/gemfiles/5.0.gemfile +17 -0
  15. data/gemfiles/5.0.gemfile.lock +179 -0
  16. data/lib/shoulda/version.rb +1 -1
  17. data/shoulda.gemspec +23 -23
  18. data/test/acceptance/rails_integration_test.rb +76 -0
  19. data/test/acceptance_test_helper.rb +17 -0
  20. data/test/report_warnings.rb +7 -0
  21. data/test/support/acceptance/add_shoulda_to_project.rb +78 -0
  22. data/test/support/acceptance/helpers.rb +19 -0
  23. data/test/support/acceptance/helpers/active_model_helpers.rb +11 -0
  24. data/test/support/acceptance/helpers/array_helpers.rb +13 -0
  25. data/test/support/acceptance/helpers/base_helpers.rb +14 -0
  26. data/test/support/acceptance/helpers/command_helpers.rb +54 -0
  27. data/test/support/acceptance/helpers/file_helpers.rb +19 -0
  28. data/test/support/acceptance/helpers/gem_helpers.rb +31 -0
  29. data/test/support/acceptance/helpers/pluralization_helpers.rb +13 -0
  30. data/test/support/acceptance/helpers/step_helpers.rb +69 -0
  31. data/test/support/acceptance/matchers/have_output.rb +31 -0
  32. data/test/support/acceptance/matchers/indicate_number_of_tests_was_run_matcher.rb +54 -0
  33. data/test/support/acceptance/matchers/indicate_that_tests_were_run_matcher.rb +75 -0
  34. data/test/support/tests/bundle.rb +94 -0
  35. data/test/support/tests/command_runner.rb +230 -0
  36. data/test/support/tests/current_bundle.rb +61 -0
  37. data/test/support/tests/filesystem.rb +100 -0
  38. data/test/support/tests/version.rb +45 -0
  39. data/test/test_helper.rb +18 -0
  40. data/test/warnings_spy.rb +62 -0
  41. data/test/warnings_spy/filesystem.rb +45 -0
  42. data/test/warnings_spy/partitioner.rb +36 -0
  43. data/test/warnings_spy/reader.rb +53 -0
  44. data/test/warnings_spy/reporter.rb +88 -0
  45. metadata +80 -121
  46. data/features/rails_integration.feature +0 -87
  47. data/features/step_definitions/rails_steps.rb +0 -77
  48. data/features/support/env.rb +0 -14
  49. data/gemfiles/3.0.gemfile +0 -7
  50. data/gemfiles/3.0.gemfile.lock +0 -127
  51. data/gemfiles/3.1.gemfile +0 -9
  52. data/gemfiles/3.1.gemfile.lock +0 -148
  53. data/gemfiles/3.2.gemfile +0 -9
  54. data/gemfiles/3.2.gemfile.lock +0 -146
@@ -0,0 +1,62 @@
1
+ require 'forwardable'
2
+
3
+ require File.expand_path('../warnings_spy/filesystem', __FILE__)
4
+ require File.expand_path('../warnings_spy/reader', __FILE__)
5
+ require File.expand_path('../warnings_spy/partitioner', __FILE__)
6
+ require File.expand_path('../warnings_spy/reporter', __FILE__)
7
+
8
+ class WarningsSpy
9
+ extend Forwardable
10
+
11
+ def initialize(project_name)
12
+ filesystem = Filesystem.new
13
+ @warnings_file = filesystem.warnings_file
14
+ @reader = Reader.new(filesystem)
15
+ @partitioner = Partitioner.new(reader, filesystem)
16
+ @reporter = Reporter.new(partitioner, filesystem, project_name)
17
+ end
18
+
19
+ def capture_warnings
20
+ $stderr.reopen(warnings_file.path)
21
+ end
22
+
23
+ def report_warnings_at_exit
24
+ at_exit do
25
+ printing_exceptions do
26
+ report_and_exit
27
+ end
28
+ end
29
+ end
30
+
31
+ protected
32
+
33
+ attr_reader :warnings_file, :reader, :partitioner, :reporter
34
+
35
+ private
36
+
37
+ def_delegators :partitioner, :relevant_warning_groups,
38
+ :irrelevant_warning_groups
39
+
40
+ def report_and_exit
41
+ reader.read
42
+ partitioner.partition
43
+ reporter.report
44
+ fail_build_if_there_are_any_warnings
45
+ end
46
+
47
+ def fail_build_if_there_are_any_warnings
48
+ if relevant_warning_groups.any?
49
+ exit(1)
50
+ end
51
+ end
52
+
53
+ def printing_exceptions
54
+ yield
55
+ rescue => error
56
+ puts "\n--- ERROR IN AT_EXIT --------------------------------"
57
+ puts "#{error.class}: #{error.message}"
58
+ puts error.backtrace.join("\n")
59
+ puts '-----------------------------------------------------'
60
+ raise error
61
+ end
62
+ end
@@ -0,0 +1,45 @@
1
+ require 'fileutils'
2
+
3
+ class WarningsSpy
4
+ class Filesystem
5
+ PROJECT_DIR = File.expand_path('../../..', __FILE__)
6
+ TEMP_DIR = File.join(PROJECT_DIR, 'tmp')
7
+
8
+ def initialize
9
+ @files_by_name = Hash.new do |hash, name|
10
+ FileUtils.mkdir_p(TEMP_DIR)
11
+ hash[name] = file_for(name)
12
+ end
13
+ end
14
+
15
+ def warnings_file
16
+ files_by_name['all_warnings']
17
+ end
18
+
19
+ def irrelevant_warnings_file
20
+ files_by_name['irrelevant_warnings']
21
+ end
22
+
23
+ def relevant_warnings_file
24
+ files_by_name['relevant_warnings']
25
+ end
26
+
27
+ def project_dir
28
+ PROJECT_DIR
29
+ end
30
+
31
+ protected
32
+
33
+ attr_reader :files_by_name
34
+
35
+ private
36
+
37
+ def path_for(name)
38
+ File.join(TEMP_DIR, "#{name}.txt")
39
+ end
40
+
41
+ def file_for(name)
42
+ File.open(path_for(name), 'w+')
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ require 'forwardable'
2
+
3
+ class WarningsSpy
4
+ class Partitioner
5
+ extend Forwardable
6
+
7
+ attr_reader :relevant_warning_groups, :irrelevant_warning_groups
8
+
9
+ def initialize(reader, filesystem)
10
+ @reader = reader
11
+ @search_text = filesystem.project_dir
12
+ end
13
+
14
+ def partition
15
+ @relevant_warning_groups, @irrelevant_warning_groups =
16
+ warning_groups.partition { |group| relevant_warnings?(group) }
17
+ end
18
+
19
+ protected
20
+
21
+ attr_reader :reader, :search_text
22
+
23
+ private
24
+
25
+ def_delegators :reader, :warning_groups
26
+
27
+ def relevant_warnings?(group)
28
+ first_line = group[0]
29
+ first_line.start_with?("#{project_root}/lib")
30
+ end
31
+
32
+ def project_root
33
+ File.expand_path('../../..')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,53 @@
1
+ class WarningsSpy
2
+ class Reader
3
+ attr_reader :warning_groups
4
+
5
+ def initialize(filesystem)
6
+ @warnings_file = filesystem.warnings_file
7
+
8
+ @current_group = []
9
+ @warning_groups = []
10
+ end
11
+
12
+ def read
13
+ warnings_file.rewind
14
+
15
+ warnings_file.each_line do |line|
16
+ process_line(line)
17
+ end
18
+
19
+ add_group(current_group)
20
+ end
21
+
22
+ protected
23
+
24
+ attr_reader :warnings_file, :current_group
25
+
26
+ private
27
+
28
+ def process_line(line)
29
+ if start_of_group?(line)
30
+ add_group(current_group)
31
+ @current_group = []
32
+ end
33
+
34
+ current_group << line
35
+ end
36
+
37
+ def start_of_group?(line)
38
+ line =~ /^\S/
39
+ end
40
+
41
+ def add_group(group)
42
+ unless group.empty? || group_already_added?(group)
43
+ warning_groups << group
44
+ end
45
+ end
46
+
47
+ def group_already_added?(group_to_be_added)
48
+ warning_groups.any? do |group|
49
+ group == group_to_be_added
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,88 @@
1
+ require 'forwardable'
2
+
3
+ class WarningsSpy
4
+ class Reporter
5
+ extend Forwardable
6
+
7
+ def initialize(partitioner, filesystem, project_name)
8
+ @partitioner = partitioner
9
+ @warnings_file = filesystem.warnings_file
10
+ @relevant_warnings_file = filesystem.relevant_warnings_file
11
+ @irrelevant_warnings_file = filesystem.irrelevant_warnings_file
12
+ @project_name = project_name
13
+ end
14
+
15
+ def report
16
+ reporting_all_groups do
17
+ report_relevant_warning_groups
18
+ report_irrelevant_warning_groups
19
+ end
20
+ end
21
+
22
+ protected
23
+
24
+ attr_reader :partitioner, :warnings_file, :relevant_warnings_file,
25
+ :irrelevant_warnings_file, :project_name
26
+
27
+ private
28
+
29
+ def_delegators :partitioner, :relevant_warning_groups,
30
+ :irrelevant_warning_groups
31
+
32
+ def report_relevant_warning_groups
33
+ if relevant_warning_groups.any?
34
+ print_divider('-', 75, header: " #{project_name} warnings:")
35
+ relevant_warning_groups.each do |group|
36
+ group.each do |line|
37
+ relevant_warnings_file.puts(line)
38
+ puts line
39
+ end
40
+ end
41
+ print_divider('-', 75)
42
+ puts "#{project_name} warnings written to #{relevant_warnings_file.path}."
43
+ end
44
+ end
45
+
46
+ def report_irrelevant_warning_groups
47
+ if irrelevant_warning_groups.any?
48
+ irrelevant_warning_groups.each do |group|
49
+ group.each do |line|
50
+ irrelevant_warnings_file.puts(line)
51
+ end
52
+ end
53
+ puts "Non #{project_name} warnings were raised during the test run. These have been written to #{irrelevant_warnings_file.path}."
54
+ end
55
+ end
56
+
57
+ def reporting_all_groups
58
+ if relevant_warning_groups.any? || irrelevant_warning_groups.any?
59
+ puts
60
+ yield
61
+ puts "All warnings were written to #{warnings_file.path}."
62
+ puts
63
+ end
64
+ end
65
+
66
+ def print_divider(character, count, options = {})
67
+ puts
68
+
69
+ if options[:header]
70
+ first_count = 10
71
+ second_count = options[:header].length - first_count
72
+ string =
73
+ horizontal_rule(character, first_count) +
74
+ options[:header] +
75
+ horizontal_rule(character, second_count)
76
+ puts string
77
+ else
78
+ puts horizontal_rule(character, count)
79
+ end
80
+
81
+ puts
82
+ end
83
+
84
+ def horizontal_rule(character, count)
85
+ character * count
86
+ end
87
+ end
88
+ end
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.5.0
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tammer Saleh
@@ -12,159 +12,94 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-05-07 00:00:00.000000000 Z
15
+ date: 2018-07-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
+ name: shoulda-context
18
19
  requirement: !ruby/object:Gem::Requirement
19
20
  requirements:
20
- - - ~>
21
+ - - "~>"
21
22
  - !ruby/object:Gem::Version
22
23
  version: '1.0'
23
- - - ! '>='
24
+ - - ">="
24
25
  - !ruby/object:Gem::Version
25
26
  version: 1.0.1
27
+ type: :runtime
28
+ prerelease: false
26
29
  version_requirements: !ruby/object:Gem::Requirement
27
30
  requirements:
28
- - - ~>
31
+ - - "~>"
29
32
  - !ruby/object:Gem::Version
30
33
  version: '1.0'
31
- - - ! '>='
34
+ - - ">="
32
35
  - !ruby/object:Gem::Version
33
36
  version: 1.0.1
34
- type: :runtime
35
- prerelease: false
36
- name: shoulda-context
37
37
  - !ruby/object:Gem::Dependency
38
+ name: shoulda-matchers
38
39
  requirement: !ruby/object:Gem::Requirement
39
40
  requirements:
40
- - - ! '>='
41
- - !ruby/object:Gem::Version
42
- version: 1.4.1
43
- - - <
44
- - !ruby/object:Gem::Version
45
- version: '3.0'
46
- version_requirements: !ruby/object:Gem::Requirement
47
- requirements:
48
- - - ! '>='
49
- - !ruby/object:Gem::Version
50
- version: 1.4.1
51
- - - <
41
+ - - "~>"
52
42
  - !ruby/object:Gem::Version
53
43
  version: '3.0'
54
44
  type: :runtime
55
45
  prerelease: false
56
- name: shoulda-matchers
57
- - !ruby/object:Gem::Dependency
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ~>
61
- - !ruby/object:Gem::Version
62
- version: 0.4.0
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ~>
66
- - !ruby/object:Gem::Version
67
- version: 0.4.0
68
- type: :development
69
- prerelease: false
70
- name: appraisal
71
- - !ruby/object:Gem::Dependency
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - '='
75
- - !ruby/object:Gem::Version
76
- version: 3.0.12
77
- version_requirements: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - '='
80
- - !ruby/object:Gem::Version
81
- version: 3.0.12
82
- type: :development
83
- prerelease: false
84
- name: rails
85
- - !ruby/object:Gem::Dependency
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ~>
89
- - !ruby/object:Gem::Version
90
- version: 1.3.2
91
- version_requirements: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ~>
94
- - !ruby/object:Gem::Version
95
- version: 1.3.2
96
- type: :development
97
- prerelease: false
98
- name: sqlite3
99
- - !ruby/object:Gem::Dependency
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - ~>
103
- - !ruby/object:Gem::Version
104
- version: 2.7.0
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: 2.7.0
110
- type: :development
111
- prerelease: false
112
- name: rspec-rails
113
- - !ruby/object:Gem::Dependency
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ~>
117
- - !ruby/object:Gem::Version
118
- version: 1.1.0
119
46
  version_requirements: !ruby/object:Gem::Requirement
120
47
  requirements:
121
- - - ~>
48
+ - - "~>"
122
49
  - !ruby/object:Gem::Version
123
- version: 1.1.0
124
- type: :development
125
- prerelease: false
126
- name: cucumber
127
- - !ruby/object:Gem::Dependency
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - ~>
131
- - !ruby/object:Gem::Version
132
- version: 0.4.11
133
- version_requirements: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - ~>
136
- - !ruby/object:Gem::Version
137
- version: 0.4.11
138
- type: :development
139
- prerelease: false
140
- name: aruba
50
+ version: '3.0'
141
51
  description: Making tests easy on the fingers and eyes
142
52
  email: support@thoughtbot.com
143
53
  executables: []
144
54
  extensions: []
145
55
  extra_rdoc_files: []
146
56
  files:
147
- - .autotest
148
- - .gitignore
149
- - .travis.yml
57
+ - ".autotest"
58
+ - ".gitignore"
59
+ - ".hound.yml"
60
+ - ".hound/ruby.yml"
61
+ - ".rubocop.yml"
62
+ - ".travis.yml"
150
63
  - Appraisals
151
64
  - CONTRIBUTING.md
152
65
  - Gemfile
153
66
  - MIT-LICENSE
154
67
  - README.md
155
68
  - Rakefile
156
- - features/rails_integration.feature
157
- - features/step_definitions/rails_steps.rb
158
- - features/support/env.rb
159
- - gemfiles/3.0.gemfile
160
- - gemfiles/3.0.gemfile.lock
161
- - gemfiles/3.1.gemfile
162
- - gemfiles/3.1.gemfile.lock
163
- - gemfiles/3.2.gemfile
164
- - gemfiles/3.2.gemfile.lock
69
+ - gemfiles/4.2.gemfile
70
+ - gemfiles/4.2.gemfile.lock
71
+ - gemfiles/5.0.gemfile
72
+ - gemfiles/5.0.gemfile.lock
165
73
  - lib/shoulda.rb
166
74
  - lib/shoulda/version.rb
167
75
  - shoulda.gemspec
76
+ - test/acceptance/rails_integration_test.rb
77
+ - test/acceptance_test_helper.rb
78
+ - test/report_warnings.rb
79
+ - test/support/acceptance/add_shoulda_to_project.rb
80
+ - test/support/acceptance/helpers.rb
81
+ - test/support/acceptance/helpers/active_model_helpers.rb
82
+ - 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
+ - test/support/acceptance/helpers/pluralization_helpers.rb
88
+ - test/support/acceptance/helpers/step_helpers.rb
89
+ - 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
97
+ - 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
168
103
  homepage: https://github.com/thoughtbot/shoulda
169
104
  licenses:
170
105
  - MIT
@@ -175,21 +110,45 @@ require_paths:
175
110
  - lib
176
111
  required_ruby_version: !ruby/object:Gem::Requirement
177
112
  requirements:
178
- - - ! '>='
113
+ - - ">="
179
114
  - !ruby/object:Gem::Version
180
115
  version: '0'
181
116
  required_rubygems_version: !ruby/object:Gem::Requirement
182
117
  requirements:
183
- - - ! '>='
118
+ - - ">="
184
119
  - !ruby/object:Gem::Version
185
120
  version: '0'
186
121
  requirements: []
187
122
  rubyforge_project:
188
- rubygems_version: 2.0.3
123
+ rubygems_version: 2.7.6
189
124
  signing_key:
190
125
  specification_version: 4
191
126
  summary: Making tests easy on the fingers and eyes
192
127
  test_files:
193
- - features/rails_integration.feature
194
- - features/step_definitions/rails_steps.rb
195
- - features/support/env.rb
128
+ - test/acceptance/rails_integration_test.rb
129
+ - test/acceptance_test_helper.rb
130
+ - test/report_warnings.rb
131
+ - test/support/acceptance/add_shoulda_to_project.rb
132
+ - test/support/acceptance/helpers.rb
133
+ - test/support/acceptance/helpers/active_model_helpers.rb
134
+ - 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
+ - test/support/acceptance/helpers/pluralization_helpers.rb
140
+ - test/support/acceptance/helpers/step_helpers.rb
141
+ - 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
149
+ - 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