assert 2.16.5 → 2.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -7
  2. data/Gemfile +3 -1
  3. data/README.md +20 -20
  4. data/assert.gemspec +5 -3
  5. data/bin/assert +4 -4
  6. data/lib/assert.rb +8 -8
  7. data/lib/assert/assert_runner.rb +7 -7
  8. data/lib/assert/assertions.rb +5 -5
  9. data/lib/assert/cli.rb +35 -35
  10. data/lib/assert/config.rb +8 -8
  11. data/lib/assert/config_helpers.rb +6 -6
  12. data/lib/assert/context.rb +17 -17
  13. data/lib/assert/context/test_dsl.rb +5 -5
  14. data/lib/assert/context_info.rb +2 -2
  15. data/lib/assert/default_runner.rb +1 -1
  16. data/lib/assert/default_suite.rb +1 -1
  17. data/lib/assert/default_view.rb +8 -8
  18. data/lib/assert/factory.rb +1 -1
  19. data/lib/assert/macro.rb +1 -1
  20. data/lib/assert/macros/methods.rb +1 -1
  21. data/lib/assert/result.rb +17 -17
  22. data/lib/assert/runner.rb +12 -8
  23. data/lib/assert/stub.rb +1 -1
  24. data/lib/assert/suite.rb +3 -3
  25. data/lib/assert/test.rb +11 -11
  26. data/lib/assert/utils.rb +8 -8
  27. data/lib/assert/version.rb +1 -1
  28. data/lib/assert/view.rb +19 -19
  29. data/lib/assert/view_helpers.rb +6 -6
  30. data/test/helper.rb +2 -11
  31. data/test/support/factory.rb +6 -6
  32. data/test/system/stub_tests.rb +204 -204
  33. data/test/system/test_tests.rb +13 -13
  34. data/test/unit/assert_tests.rb +9 -9
  35. data/test/unit/assertions/assert_block_tests.rb +2 -2
  36. data/test/unit/assertions/assert_empty_tests.rb +6 -6
  37. data/test/unit/assertions/assert_equal_tests.rb +5 -5
  38. data/test/unit/assertions/assert_file_exists_tests.rb +6 -6
  39. data/test/unit/assertions/assert_includes_tests.rb +7 -7
  40. data/test/unit/assertions/assert_instance_of_tests.rb +5 -5
  41. data/test/unit/assertions/assert_kind_of_tests.rb +5 -5
  42. data/test/unit/assertions/assert_match_tests.rb +5 -5
  43. data/test/unit/assertions/assert_nil_tests.rb +5 -5
  44. data/test/unit/assertions/assert_raises_tests.rb +2 -2
  45. data/test/unit/assertions/assert_respond_to_tests.rb +5 -5
  46. data/test/unit/assertions/assert_same_tests.rb +13 -13
  47. data/test/unit/assertions/assert_true_false_tests.rb +7 -7
  48. data/test/unit/assertions_tests.rb +2 -2
  49. data/test/unit/config_helpers_tests.rb +5 -5
  50. data/test/unit/config_tests.rb +12 -12
  51. data/test/unit/context/setup_dsl_tests.rb +7 -7
  52. data/test/unit/context/subject_dsl_tests.rb +3 -3
  53. data/test/unit/context/suite_dsl_tests.rb +3 -3
  54. data/test/unit/context/test_dsl_tests.rb +8 -8
  55. data/test/unit/context_info_tests.rb +6 -6
  56. data/test/unit/context_tests.rb +16 -16
  57. data/test/unit/default_runner_tests.rb +3 -3
  58. data/test/unit/default_suite_tests.rb +3 -3
  59. data/test/unit/factory_tests.rb +3 -3
  60. data/test/unit/file_line_tests.rb +12 -12
  61. data/test/unit/macro_tests.rb +2 -2
  62. data/test/unit/result_tests.rb +18 -18
  63. data/test/unit/runner_tests.rb +9 -9
  64. data/test/unit/suite_tests.rb +5 -5
  65. data/test/unit/test_tests.rb +19 -19
  66. data/test/unit/utils_tests.rb +18 -18
  67. data/test/unit/view_helpers_tests.rb +15 -15
  68. data/test/unit/view_tests.rb +11 -11
  69. data/tmp/.gitkeep +0 -0
  70. metadata +46 -44
  71. data/.assert.rb +0 -3
  72. data/.gitignore +0 -19
@@ -33,27 +33,27 @@ module Assert
33
33
  self.pass_result_count == self.result_count
34
34
  end
35
35
 
36
- def formatted_run_time(run_time, format = '%.6f')
36
+ def formatted_run_time(run_time, format = "%.6f")
37
37
  format % run_time
38
38
  end
39
39
 
40
- def formatted_test_rate(test_rate, format = '%.6f')
40
+ def formatted_test_rate(test_rate, format = "%.6f")
41
41
  format % test_rate
42
42
  end
43
43
 
44
- def formatted_result_rate(result_rate, format = '%.6f')
44
+ def formatted_result_rate(result_rate, format = "%.6f")
45
45
  format % result_rate
46
46
  end
47
47
 
48
- def formatted_suite_run_time(format = '%.6f')
48
+ def formatted_suite_run_time(format = "%.6f")
49
49
  formatted_run_time(self.config.suite.run_time, format)
50
50
  end
51
51
 
52
- def formatted_suite_test_rate(format = '%.6f')
52
+ def formatted_suite_test_rate(format = "%.6f")
53
53
  formatted_test_rate(self.config.suite.test_rate, format)
54
54
  end
55
55
 
56
- def formatted_suite_result_rate(format = '%.6f')
56
+ def formatted_suite_result_rate(format = "%.6f")
57
57
  formatted_result_rate(self.config.suite.result_rate, format)
58
58
  end
59
59
 
@@ -1,13 +1,13 @@
1
- require 'assert/assertions'
2
- require 'assert/context/setup_dsl'
3
- require 'assert/context/subject_dsl'
4
- require 'assert/context/suite_dsl'
5
- require 'assert/context/test_dsl'
6
- require 'assert/context_info'
7
- require 'assert/macros/methods'
8
- require 'assert/result'
9
- require 'assert/suite'
10
- require 'assert/utils'
1
+ require "assert/assertions"
2
+ require "assert/context/setup_dsl"
3
+ require "assert/context/subject_dsl"
4
+ require "assert/context/suite_dsl"
5
+ require "assert/context/test_dsl"
6
+ require "assert/context_info"
7
+ require "assert/macros/methods"
8
+ require "assert/result"
9
+ require "assert/suite"
10
+ require "assert/utils"
11
11
 
12
12
  module Assert
13
13
 
@@ -33,7 +33,7 @@ module Assert
33
33
  klass_method_name = "#{self}##{method_name}"
34
34
 
35
35
  if self.suite.test_methods.include?(klass_method_name)
36
- puts "WARNING: redefining '#{klass_method_name}'"
36
+ puts "WARNING: redefining "#{klass_method_name}""
37
37
  puts " from: #{caller_locations(1,1)}"
38
38
  else
39
39
  self.suite.test_methods << klass_method_name
@@ -111,15 +111,15 @@ module Assert
111
111
  def fail(message = nil)
112
112
  if @__assert_pending__ == 0
113
113
  if halt_on_fail?
114
- raise Result::TestFailure, message || ''
114
+ raise Result::TestFailure, message || ""
115
115
  else
116
- capture_result(Assert::Result::Fail, message || '')
116
+ capture_result(Assert::Result::Fail, message || "")
117
117
  end
118
118
  else
119
119
  if halt_on_fail?
120
- raise Result::TestSkipped, "Pending fail: #{message || ''}"
120
+ raise Result::TestSkipped, "Pending fail: #{message || ""}"
121
121
  else
122
- capture_result(Assert::Result::Skip, "Pending fail: #{message || ''}")
122
+ capture_result(Assert::Result::Skip, "Pending fail: #{message || ""}")
123
123
  end
124
124
  end
125
125
  end
@@ -128,7 +128,7 @@ module Assert
128
128
  # adds a Skip result to the end of the test's results
129
129
  # breaks test execution
130
130
  def skip(skip_msg = nil, called_from = nil)
131
- raise Result::TestSkipped, (skip_msg || ''), called_from
131
+ raise Result::TestSkipped, (skip_msg || ""), called_from
132
132
  end
133
133
 
134
134
  # runs block and any fails are skips and any passes are fails
@@ -172,7 +172,7 @@ module Assert
172
172
  # Returns a Proc that will output a custom message along with the default
173
173
  # fail message.
174
174
  def fail_message(fail_desc = nil, what_failed_msg = nil)
175
- [ fail_desc, what_failed_msg ].compact.join("\n")
175
+ [fail_desc, what_failed_msg].compact.join("\n")
176
176
  end
177
177
 
178
178
  private
@@ -1,7 +1,7 @@
1
- require 'assert/context_info'
2
- require 'assert/macro'
3
- require 'assert/suite'
4
- require 'assert/test'
1
+ require "assert/context_info"
2
+ require "assert/macro"
3
+ require "assert/suite"
4
+ require "assert/test"
5
5
 
6
6
  module Assert; end
7
7
  class Assert::Context
@@ -31,7 +31,7 @@ class Assert::Context
31
31
  desc_or_macro.kind_of?(Assert::Macro) ? desc_or_macro.name : desc_or_macro,
32
32
  ci,
33
33
  self.suite.config,
34
- &proc { skip('TODO', [ci.called_from.to_s]) }
34
+ &proc { skip("TODO", [ci.called_from.to_s]) }
35
35
  ))
36
36
  end
37
37
  alias_method :test_skip, :test_eventually
@@ -7,11 +7,11 @@ module Assert
7
7
  def initialize(klass, called_from = nil, first_caller = nil)
8
8
  @called_from = called_from || first_caller
9
9
  @klass = klass
10
- @file = @called_from.to_s.gsub(/\:[0-9]+.*$/, '') if @called_from
10
+ @file = @called_from.to_s.gsub(/\:[0-9]+.*$/, "") if @called_from
11
11
  end
12
12
 
13
13
  def test_name(name)
14
- [klass.description.to_s, name.to_s].compact.reject(&:empty?).join(' ')
14
+ [klass.description.to_s, name.to_s].compact.reject(&:empty?).join(" ")
15
15
  end
16
16
 
17
17
  end
@@ -1,4 +1,4 @@
1
- require 'assert/runner'
1
+ require "assert/runner"
2
2
 
3
3
  module Assert
4
4
 
@@ -1,4 +1,4 @@
1
- require 'assert/suite'
1
+ require "assert/suite"
2
2
 
3
3
  module Assert
4
4
 
@@ -1,5 +1,5 @@
1
- require 'assert/view'
2
- require 'assert/view_helpers'
1
+ require "assert/view"
2
+ require "assert/view_helpers"
3
3
 
4
4
  module Assert
5
5
 
@@ -11,12 +11,12 @@ module Assert
11
11
 
12
12
  # setup options and their default values
13
13
 
14
- option 'styled', true
15
- option 'pass_styles', :green
16
- option 'fail_styles', :red, :bold
17
- option 'error_styles', :yellow, :bold
18
- option 'skip_styles', :cyan
19
- option 'ignore_styles', :magenta
14
+ option "styled", true
15
+ option "pass_styles", :green
16
+ option "fail_styles", :red, :bold
17
+ option "error_styles", :yellow, :bold
18
+ option "skip_styles", :cyan
19
+ option "ignore_styles", :magenta
20
20
 
21
21
  def before_load(test_files)
22
22
  end
@@ -1,4 +1,4 @@
1
- require 'much-factory'
1
+ require "much-factory"
2
2
 
3
3
  module Assert
4
4
 
@@ -2,7 +2,7 @@ module Assert
2
2
  class Macro < ::Proc
3
3
 
4
4
  # this class is essentially a way to define a custom set of tests using
5
- # arguments. When passed as an argument to the 'should' method, a macro
5
+ # arguments. When passed as an argument to the "should" method, a macro
6
6
  # will be instance_eval'd in that Assert::Context.
7
7
 
8
8
  attr_accessor :name
@@ -1,4 +1,4 @@
1
- require 'assert/macro'
1
+ require "assert/macro"
2
2
 
3
3
  module Assert::Macros
4
4
  module Methods
@@ -1,4 +1,4 @@
1
- require 'assert/file_line'
1
+ require "assert/file_line"
2
2
 
3
3
  module Assert; end
4
4
  module Assert::Result
@@ -28,7 +28,7 @@ module Assert::Result
28
28
  class Base
29
29
 
30
30
  def self.type; :unknown; end
31
- def self.name; ''; end
31
+ def self.name; ""; end
32
32
 
33
33
  def self.for_test(test, message, bt)
34
34
  self.new({
@@ -54,11 +54,11 @@ module Assert::Result
54
54
  end
55
55
 
56
56
  def test_name
57
- @test_name ||= (@build_data[:test_name] || '')
57
+ @test_name ||= (@build_data[:test_name] || "")
58
58
  end
59
59
 
60
60
  def test_file_line
61
- @test_file_line ||= (@build_data[:test_file_line] || Assert::FileLine.parse(''))
61
+ @test_file_line ||= (@build_data[:test_file_line] || Assert::FileLine.parse(""))
62
62
  end
63
63
 
64
64
  def test_file_name; self.test_file_line.file; end
@@ -69,11 +69,11 @@ module Assert::Result
69
69
  end
70
70
 
71
71
  def message
72
- @message ||= (@build_data[:message] || '')
72
+ @message ||= (@build_data[:message] || "")
73
73
  end
74
74
 
75
75
  def output
76
- @output ||= (@build_data[:output] || '')
76
+ @output ||= (@build_data[:output] || "")
77
77
  end
78
78
 
79
79
  def backtrace
@@ -135,7 +135,7 @@ module Assert::Result
135
135
  end
136
136
 
137
137
  def inspect
138
- "#<#{self.class}:#{'0x0%x' % (object_id << 1)} "\
138
+ "#<#{self.class}:#{"0x0%x" % (object_id << 1)} "\
139
139
  "@message=#{self.message.inspect} "\
140
140
  "@file_line=#{self.file_line.to_s.inspect} "\
141
141
  "@test_file_line=#{self.test_file_line.to_s.inspect}>"
@@ -166,14 +166,14 @@ module Assert::Result
166
166
  class Pass < Base
167
167
 
168
168
  def self.type; :pass; end
169
- def self.name; 'Pass'; end
169
+ def self.name; "Pass"; end
170
170
 
171
171
  end
172
172
 
173
173
  class Ignore < Base
174
174
 
175
175
  def self.type; :ignore; end
176
- def self.name; 'Ignore'; end
176
+ def self.name; "Ignore"; end
177
177
 
178
178
  end
179
179
 
@@ -181,13 +181,13 @@ module Assert::Result
181
181
  attr_accessor :assert_with_bt
182
182
  end
183
183
 
184
- # raised by the 'fail' context helper to break test execution
184
+ # raised by the "fail" context helper to break test execution
185
185
  TestFailure = Class.new(HaltingTestResultError)
186
186
 
187
187
  class Fail < Base
188
188
 
189
189
  def self.type; :fail; end
190
- def self.name; 'Fail'; end
190
+ def self.name; "Fail"; end
191
191
 
192
192
  # fail results can be generated manually or by raising Assert::Result::TestFailure
193
193
  def self.for_test(test, msg_or_err, bt = nil)
@@ -204,13 +204,13 @@ module Assert::Result
204
204
 
205
205
  end
206
206
 
207
- # raised by the 'skip' context helper to break test execution
207
+ # raised by the "skip" context helper to break test execution
208
208
  TestSkipped = Class.new(HaltingTestResultError)
209
209
 
210
210
  class Skip < Base
211
211
 
212
212
  def self.type; :skip; end
213
- def self.name; 'Skip'; end
213
+ def self.name; "Skip"; end
214
214
 
215
215
  # skip results are generated by raising Assert::Result::TestSkipped
216
216
  def self.for_test(test, msg_or_err, bt = nil)
@@ -230,7 +230,7 @@ module Assert::Result
230
230
  class Error < Base
231
231
 
232
232
  def self.type; :error; end
233
- def self.name; 'Error'; end
233
+ def self.name; "Error"; end
234
234
 
235
235
  # error results are generated by raising exceptions in tests
236
236
  def self.for_test(test, err)
@@ -274,9 +274,9 @@ module Assert::Result
274
274
 
275
275
  # filter a line out if it's an assert lib/bin line
276
276
  def filter_out?(line)
277
- # './lib' in project dir, or '/usr/local/blahblah' if installed
278
- assert_lib_path = File.expand_path('../..', __FILE__)
279
- assert_macros_path = File.join(assert_lib_path, 'assert/macros')
277
+ # "./lib" in project dir, or "/usr/local/blahblah" if installed
278
+ assert_lib_path = File.expand_path("../..", __FILE__)
279
+ assert_macros_path = File.join(assert_lib_path, "assert/macros")
280
280
  assert_bin_regex = /bin\/assert\:/
281
281
  ( line.rindex(assert_lib_path, 0) &&
282
282
  !line.rindex(assert_macros_path, 0)
@@ -1,6 +1,6 @@
1
- require 'assert/config_helpers'
2
- require 'assert/suite'
3
- require 'assert/view'
1
+ require "assert/config_helpers"
2
+ require "assert/suite"
3
+ require "assert/view"
4
4
 
5
5
  module Assert
6
6
 
@@ -29,12 +29,16 @@ module Assert
29
29
  self.view.puts ", seeded with \"#{self.runner_seed}\""
30
30
  end
31
31
 
32
- # if INFO signal requested (Ctrl+T on Macs), process it
33
32
  @current_running_test = nil
34
- trap("INFO") do
35
- self.on_info(@current_running_test)
36
- self.suite.on_info(@current_running_test)
37
- self.view.on_info(@current_running_test)
33
+
34
+ # if SIGINFO available (ie on OSX, not on BSD) and if SIGINFO requested
35
+ # (Ctrl+T on Macs), process it
36
+ if Signal.list.keys.include?("INFO")
37
+ Signal.trap("INFO") do
38
+ self.on_info(@current_running_test)
39
+ self.suite.on_info(@current_running_test)
40
+ self.view.on_info(@current_running_test)
41
+ end
38
42
  end
39
43
 
40
44
  begin
@@ -1,4 +1,4 @@
1
- require 'much-stub'
1
+ require "much-stub"
2
2
 
3
3
  module Assert
4
4
 
@@ -1,5 +1,5 @@
1
- require 'assert/config_helpers'
2
- require 'assert/test'
1
+ require "assert/config_helpers"
2
+ require "assert/test"
3
3
 
4
4
  module Assert
5
5
 
@@ -97,7 +97,7 @@ module Assert
97
97
  def on_interrupt(err); end
98
98
 
99
99
  def inspect
100
- "#<#{self.class}:#{'0x0%x' % (object_id << 1)}"\
100
+ "#<#{self.class}:#{"0x0%x" % (object_id << 1)}"\
101
101
  " test_count=#{self.test_count.inspect}"\
102
102
  " result_count=#{self.result_count.inspect}>"
103
103
  end
@@ -1,6 +1,6 @@
1
- require 'stringio'
2
- require 'assert/file_line'
3
- require 'assert/result'
1
+ require "stringio"
2
+ require "assert/file_line"
3
+ require "assert/result"
4
4
 
5
5
  module Assert
6
6
 
@@ -37,18 +37,18 @@ module Assert
37
37
  end
38
38
 
39
39
  def file_line
40
- @file_line ||= FileLine.parse((@build_data[:file_line] || '').to_s)
40
+ @file_line ||= FileLine.parse((@build_data[:file_line] || "").to_s)
41
41
  end
42
42
 
43
43
  def file_name; self.file_line.file; end
44
44
  def line_num; self.file_line.line.to_i; end
45
45
 
46
46
  def name
47
- @name ||= (@build_data[:name] || '')
47
+ @name ||= (@build_data[:name] || "")
48
48
  end
49
49
 
50
50
  def output
51
- @output ||= (@build_data[:output] || '')
51
+ @output ||= (@build_data[:output] || "")
52
52
  end
53
53
 
54
54
  def run_time
@@ -90,16 +90,16 @@ module Assert
90
90
  attributes_string = ([:name, :context_info].collect do |attr|
91
91
  "@#{attr}=#{self.send(attr).inspect}"
92
92
  end).join(" ")
93
- "#<#{self.class}:#{'0x0%x' % (object_id << 1)} #{attributes_string}>"
93
+ "#<#{self.class}:#{"0x0%x" % (object_id << 1)} #{attributes_string}>"
94
94
  end
95
95
 
96
96
  private
97
97
 
98
98
  def run_test(scope)
99
99
  begin
100
- # run any assert style 'setup do' setups
100
+ # run any assert style "setup do" setups
101
101
  self.context_class.run_setups(scope)
102
- # run any test/unit style 'def setup' setups
102
+ # run any test/unit style "def setup" setups
103
103
  scope.setup if scope.respond_to?(:setup)
104
104
  # run the code block
105
105
  scope.instance_eval(&(self.code || proc{}))
@@ -113,9 +113,9 @@ module Assert
113
113
  capture_result(Result::Error, err)
114
114
  ensure
115
115
  begin
116
- # run any assert style 'teardown do' teardowns
116
+ # run any assert style "teardown do" teardowns
117
117
  self.context_class.run_teardowns(scope)
118
- # run any test/unit style 'def teardown' teardowns
118
+ # run any test/unit style "def teardown" teardowns
119
119
  scope.teardown if scope.respond_to?(:teardown)
120
120
  rescue Result::TestFailure => err
121
121
  capture_result(Result::Fail, err)
@@ -1,4 +1,4 @@
1
- require 'assert'
1
+ require "assert"
2
2
 
3
3
  module Assert
4
4
 
@@ -16,7 +16,7 @@ module Assert
16
16
  # expands on the basic `show` util by escaping newlines and making object id
17
17
  # hex-values generic.
18
18
  def self.show_for_diff(obj, config)
19
- show(obj, config).gsub(/\\n/, "\n").gsub(/:0x[a-fA-F0-9]{4,}/m, ':0xXXXXXX')
19
+ show(obj, config).gsub(/\\n/, "\n").gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX")
20
20
  end
21
21
 
22
22
  # open a tempfile and yield it
@@ -30,8 +30,8 @@ module Assert
30
30
 
31
31
  # Get a proc that uses stdlib `PP.pp` to pretty print objects
32
32
  def self.stdlib_pp_proc(width = nil)
33
- require 'pp'
34
- Proc.new{ |obj| PP.pp(obj, '', width || 79).strip }
33
+ require "pp"
34
+ Proc.new{ |obj| PP.pp(obj, "", width || 79).strip }
35
35
  end
36
36
 
37
37
  # Return true if if either show output has newlines or is bigger than 29 chars
@@ -46,8 +46,8 @@ module Assert
46
46
  def self.syscmd_diff_proc(syscmd = "diff --unified=-1")
47
47
  Proc.new do |exp_show_output, act_show_output|
48
48
  result = ""
49
- tempfile('exp_show_output', exp_show_output) do |a|
50
- tempfile('act_show_output', act_show_output) do |b|
49
+ tempfile("exp_show_output", exp_show_output) do |a|
50
+ tempfile("act_show_output", act_show_output) do |b|
51
51
  result = `#{syscmd} #{a.path} #{b.path}`.strip
52
52
  result.sub!(/^\-\-\- .+/, "--- expected")
53
53
  result.sub!(/^\+\+\+ .+/, "+++ actual")
@@ -65,8 +65,8 @@ module Assert
65
65
  cmd = [
66
66
  "git diff --no-ext-diff --name-only #{config.changed_ref}", # changed files
67
67
  "git ls-files --others --exclude-standard" # added files
68
- ].map{ |c| "#{c} -- #{test_paths.join(' ')}" }.join(' && ')
69
- Assert::CLI.bench('Load only changed files') do
68
+ ].map{ |c| "#{c} -- #{test_paths.join(" ")}" }.join(" && ")
69
+ Assert::CLI.bench("Load only changed files") do
70
70
  files = `#{cmd}`.split("\n")
71
71
  end
72
72
  puts Assert::CLI.debug_msg(" `#{cmd}`") if config.debug