assert 2.16.5 → 2.18.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -7
  2. data/Gemfile +3 -1
  3. data/README.md +79 -54
  4. data/assert.gemspec +6 -5
  5. data/bin/assert +4 -4
  6. data/lib/assert.rb +8 -18
  7. data/lib/assert/actual_value.rb +127 -0
  8. data/lib/assert/assert_runner.rb +7 -10
  9. data/lib/assert/assertions.rb +15 -28
  10. data/lib/assert/cli.rb +41 -57
  11. data/lib/assert/config.rb +8 -12
  12. data/lib/assert/config_helpers.rb +6 -10
  13. data/lib/assert/context.rb +30 -24
  14. data/lib/assert/context/let_dsl.rb +13 -0
  15. data/lib/assert/context/method_missing.rb +19 -0
  16. data/lib/assert/context/setup_dsl.rb +0 -4
  17. data/lib/assert/context/subject_dsl.rb +0 -4
  18. data/lib/assert/context/suite_dsl.rb +0 -4
  19. data/lib/assert/context/test_dsl.rb +5 -9
  20. data/lib/assert/context_info.rb +2 -6
  21. data/lib/assert/default_runner.rb +1 -5
  22. data/lib/assert/default_suite.rb +1 -6
  23. data/lib/assert/default_view.rb +8 -12
  24. data/lib/assert/factory.rb +1 -4
  25. data/lib/assert/file_line.rb +0 -4
  26. data/lib/assert/macro.rb +1 -4
  27. data/lib/assert/macros/methods.rb +5 -11
  28. data/lib/assert/result.rb +19 -34
  29. data/lib/assert/runner.rb +12 -11
  30. data/lib/assert/stub.rb +16 -2
  31. data/lib/assert/suite.rb +3 -7
  32. data/lib/assert/test.rb +13 -18
  33. data/lib/assert/utils.rb +8 -12
  34. data/lib/assert/version.rb +1 -1
  35. data/lib/assert/view.rb +18 -21
  36. data/lib/assert/view_helpers.rb +6 -17
  37. data/log/{.gitkeep → .keep} +0 -0
  38. data/test/helper.rb +26 -41
  39. data/test/support/factory.rb +20 -6
  40. data/test/support/inherited_stuff.rb +0 -2
  41. data/test/system/stub_tests.rb +350 -354
  42. data/test/system/test_tests.rb +119 -133
  43. data/test/unit/actual_value_tests.rb +335 -0
  44. data/test/unit/assert_tests.rb +125 -52
  45. data/test/unit/assertions/assert_block_tests.rb +34 -37
  46. data/test/unit/assertions/assert_empty_tests.rb +38 -38
  47. data/test/unit/assertions/assert_equal_tests.rb +84 -86
  48. data/test/unit/assertions/assert_file_exists_tests.rb +37 -39
  49. data/test/unit/assertions/assert_includes_tests.rb +45 -46
  50. data/test/unit/assertions/assert_instance_of_tests.rb +39 -40
  51. data/test/unit/assertions/assert_kind_of_tests.rb +39 -40
  52. data/test/unit/assertions/assert_match_tests.rb +39 -40
  53. data/test/unit/assertions/assert_nil_tests.rb +35 -38
  54. data/test/unit/assertions/assert_raises_tests.rb +58 -62
  55. data/test/unit/assertions/assert_respond_to_tests.rb +41 -42
  56. data/test/unit/assertions/assert_same_tests.rb +94 -90
  57. data/test/unit/assertions/assert_true_false_tests.rb +67 -69
  58. data/test/unit/assertions_tests.rb +17 -19
  59. data/test/unit/config_helpers_tests.rb +41 -43
  60. data/test/unit/config_tests.rb +42 -46
  61. data/test/unit/context/let_dsl_tests.rb +10 -0
  62. data/test/unit/context/setup_dsl_tests.rb +72 -91
  63. data/test/unit/context/subject_dsl_tests.rb +18 -51
  64. data/test/unit/context/suite_dsl_tests.rb +19 -23
  65. data/test/unit/context/test_dsl_tests.rb +52 -59
  66. data/test/unit/context_info_tests.rb +19 -21
  67. data/test/unit/context_tests.rb +175 -178
  68. data/test/unit/default_runner_tests.rb +4 -10
  69. data/test/unit/default_suite_tests.rb +54 -59
  70. data/test/unit/factory_tests.rb +6 -9
  71. data/test/unit/file_line_tests.rb +34 -40
  72. data/test/unit/macro_tests.rb +11 -20
  73. data/test/unit/result_tests.rb +156 -182
  74. data/test/unit/runner_tests.rb +72 -79
  75. data/test/unit/suite_tests.rb +62 -63
  76. data/test/unit/test_tests.rb +143 -147
  77. data/test/unit/utils_tests.rb +49 -62
  78. data/test/unit/view_helpers_tests.rb +67 -70
  79. data/test/unit/view_tests.rb +26 -32
  80. metadata +54 -47
  81. data/.assert.rb +0 -3
  82. data/.gitignore +0 -19
@@ -1,9 +1,8 @@
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
-
7
6
  class Runner
8
7
  include Assert::ConfigHelpers
9
8
 
@@ -29,12 +28,16 @@ module Assert
29
28
  self.view.puts ", seeded with \"#{self.runner_seed}\""
30
29
  end
31
30
 
32
- # if INFO signal requested (Ctrl+T on Macs), process it
33
31
  @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)
32
+
33
+ # if SIGINFO available (ie on OSX, not on BSD) and if SIGINFO requested
34
+ # (Ctrl+T on Macs), process it
35
+ if Signal.list.keys.include?("INFO")
36
+ Signal.trap("INFO") do
37
+ self.on_info(@current_running_test)
38
+ self.suite.on_info(@current_running_test)
39
+ self.view.on_info(@current_running_test)
40
+ end
38
41
  end
39
42
 
40
43
  begin
@@ -99,7 +102,5 @@ module Assert
99
102
  self.suite.sorted_tests_to_run{ rand self.tests_to_run_count }
100
103
  end
101
104
  end
102
-
103
105
  end
104
-
105
106
  end
@@ -1,7 +1,6 @@
1
- require 'much-stub'
1
+ require "much-stub"
2
2
 
3
3
  module Assert
4
-
5
4
  def self.stubs
6
5
  MuchStub.stubs
7
6
  end
@@ -10,6 +9,10 @@ module Assert
10
9
  MuchStub.stub(*args, &block)
11
10
  end
12
11
 
12
+ def self.stub_on_call(*args, &block)
13
+ MuchStub.stub_on_call(*args, &block)
14
+ end
15
+
13
16
  def self.unstub(*args)
14
17
  MuchStub.unstub(*args)
15
18
  end
@@ -28,4 +31,15 @@ module Assert
28
31
  end
29
32
  end
30
33
 
34
+ def self.stub_tap(*args, &block)
35
+ MuchStub.tap(*args, &block)
36
+ end
37
+
38
+ def self.stub_tap_on_call(*args, &block)
39
+ MuchStub.tap_on_call(*args, &block)
40
+ end
41
+
42
+ def self.stub_spy(*args, &block)
43
+ MuchStub.spy(*args, &block)
44
+ end
31
45
  end
@@ -1,14 +1,12 @@
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
-
6
5
  # This is the base suite. It loads the tests to run in memory and provides
7
6
  # methods for these tests that the runner/view uses for handling and
8
7
  # presentation purposes. It also stores suite-level setups and teardowns.
9
8
  # Override the test/result count methods and the callbacks as needed. See
10
9
  # the default suite for example usage.
11
-
12
10
  class Suite
13
11
  include Assert::ConfigHelpers
14
12
 
@@ -97,11 +95,9 @@ module Assert
97
95
  def on_interrupt(err); end
98
96
 
99
97
  def inspect
100
- "#<#{self.class}:#{'0x0%x' % (object_id << 1)}"\
98
+ "#<#{self.class}:#{"0x0%x" % (object_id << 1)}"\
101
99
  " test_count=#{self.test_count.inspect}"\
102
100
  " result_count=#{self.result_count.inspect}>"
103
101
  end
104
-
105
102
  end
106
-
107
103
  end
@@ -1,14 +1,11 @@
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
-
7
6
  class Test
8
-
9
- # a Test is some code/method to run in the scope of a Context that may
10
- # produce results
11
-
7
+ # Test is some code/method to run in the scope of a Context that may
8
+ # produce results.
12
9
  def self.name_file_line_context_data(ci, name)
13
10
  { :name => ci.test_name(name),
14
11
  :file_line => ci.called_from
@@ -37,18 +34,18 @@ module Assert
37
34
  end
38
35
 
39
36
  def file_line
40
- @file_line ||= FileLine.parse((@build_data[:file_line] || '').to_s)
37
+ @file_line ||= FileLine.parse((@build_data[:file_line] || "").to_s)
41
38
  end
42
39
 
43
40
  def file_name; self.file_line.file; end
44
41
  def line_num; self.file_line.line.to_i; end
45
42
 
46
43
  def name
47
- @name ||= (@build_data[:name] || '')
44
+ @name ||= (@build_data[:name] || "")
48
45
  end
49
46
 
50
47
  def output
51
- @output ||= (@build_data[:output] || '')
48
+ @output ||= (@build_data[:output] || "")
52
49
  end
53
50
 
54
51
  def run_time
@@ -90,16 +87,16 @@ module Assert
90
87
  attributes_string = ([:name, :context_info].collect do |attr|
91
88
  "@#{attr}=#{self.send(attr).inspect}"
92
89
  end).join(" ")
93
- "#<#{self.class}:#{'0x0%x' % (object_id << 1)} #{attributes_string}>"
90
+ "#<#{self.class}:#{"0x0%x" % (object_id << 1)} #{attributes_string}>"
94
91
  end
95
92
 
96
93
  private
97
94
 
98
95
  def run_test(scope)
99
96
  begin
100
- # run any assert style 'setup do' setups
97
+ # run any assert style "setup do" setups
101
98
  self.context_class.run_setups(scope)
102
- # run any test/unit style 'def setup' setups
99
+ # run any test/unit style "def setup" setups
103
100
  scope.setup if scope.respond_to?(:setup)
104
101
  # run the code block
105
102
  scope.instance_eval(&(self.code || proc{}))
@@ -113,9 +110,9 @@ module Assert
113
110
  capture_result(Result::Error, err)
114
111
  ensure
115
112
  begin
116
- # run any assert style 'teardown do' teardowns
113
+ # run any assert style "teardown do" teardowns
117
114
  self.context_class.run_teardowns(scope)
118
- # run any test/unit style 'def teardown' teardowns
115
+ # run any test/unit style "def teardown" teardowns
119
116
  scope.teardown if scope.respond_to?(:teardown)
120
117
  rescue Result::TestFailure => err
121
118
  capture_result(Result::Fail, err)
@@ -147,7 +144,5 @@ module Assert
147
144
  def capture_io
148
145
  StringIO.new(self.output, "a+")
149
146
  end
150
-
151
147
  end
152
-
153
148
  end
@@ -1,9 +1,7 @@
1
- require 'assert'
1
+ require "assert"
2
2
 
3
3
  module Assert
4
-
5
4
  module Utils
6
-
7
5
  # show objects in a human-readable manner. Either inspects or pretty-prints
8
6
  # them depending on settings.
9
7
  def self.show(obj, config)
@@ -16,7 +14,7 @@ module Assert
16
14
  # expands on the basic `show` util by escaping newlines and making object id
17
15
  # hex-values generic.
18
16
  def self.show_for_diff(obj, config)
19
- show(obj, config).gsub(/\\n/, "\n").gsub(/:0x[a-fA-F0-9]{4,}/m, ':0xXXXXXX')
17
+ show(obj, config).gsub(/\\n/, "\n").gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX")
20
18
  end
21
19
 
22
20
  # open a tempfile and yield it
@@ -30,8 +28,8 @@ module Assert
30
28
 
31
29
  # Get a proc that uses stdlib `PP.pp` to pretty print objects
32
30
  def self.stdlib_pp_proc(width = nil)
33
- require 'pp'
34
- Proc.new{ |obj| PP.pp(obj, '', width || 79).strip }
31
+ require "pp"
32
+ Proc.new{ |obj| PP.pp(obj, "", width || 79).strip }
35
33
  end
36
34
 
37
35
  # Return true if if either show output has newlines or is bigger than 29 chars
@@ -46,8 +44,8 @@ module Assert
46
44
  def self.syscmd_diff_proc(syscmd = "diff --unified=-1")
47
45
  Proc.new do |exp_show_output, act_show_output|
48
46
  result = ""
49
- tempfile('exp_show_output', exp_show_output) do |a|
50
- tempfile('act_show_output', act_show_output) do |b|
47
+ tempfile("exp_show_output", exp_show_output) do |a|
48
+ tempfile("act_show_output", act_show_output) do |b|
51
49
  result = `#{syscmd} #{a.path} #{b.path}`.strip
52
50
  result.sub!(/^\-\-\- .+/, "--- expected")
53
51
  result.sub!(/^\+\+\+ .+/, "+++ actual")
@@ -65,18 +63,16 @@ module Assert
65
63
  cmd = [
66
64
  "git diff --no-ext-diff --name-only #{config.changed_ref}", # changed files
67
65
  "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
66
+ ].map{ |c| "#{c} -- #{test_paths.join(" ")}" }.join(" && ")
67
+ Assert::CLI.bench("Load only changed files") do
70
68
  files = `#{cmd}`.split("\n")
71
69
  end
72
70
  puts Assert::CLI.debug_msg(" `#{cmd}`") if config.debug
73
71
  files
74
72
  end
75
73
  end
76
-
77
74
  end
78
75
 
79
76
  # alias for brevity
80
77
  U = Utils
81
-
82
78
  end
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "2.16.5"
2
+ VERSION = "2.18.3"
3
3
  end
@@ -1,10 +1,9 @@
1
- require 'assert/config'
2
- require 'assert/config_helpers'
3
- require 'assert/suite'
4
- require 'assert/view_helpers'
1
+ require "assert/config"
2
+ require "assert/config_helpers"
3
+ require "assert/suite"
4
+ require "assert/view_helpers"
5
5
 
6
6
  module Assert
7
-
8
7
  class View
9
8
  include Assert::ConfigHelpers
10
9
  include Assert::ViewHelpers
@@ -15,12 +14,12 @@ module Assert
15
14
 
16
15
  def self.require_user_view(view_name)
17
16
  views_file = File.expand_path(
18
- File.join("#{ENV['HOME']}/.assert/views", view_name, 'lib', view_name)
17
+ File.join("#{ENV["HOME"]}/.assert/views", view_name, "lib", view_name)
19
18
  )
20
19
 
21
- if File.exists?(view_name) || File.exists?(view_name + '.rb')
20
+ if File.exists?(view_name) || File.exists?(view_name + ".rb")
22
21
  require view_name
23
- elsif File.exists?(views_file + '.rb')
22
+ elsif File.exists?(views_file + ".rb")
24
23
  require views_file
25
24
  else
26
25
  msg = "[WARN] Can't find or require #{view_name.inspect} view."
@@ -31,18 +30,18 @@ module Assert
31
30
 
32
31
  # setup options and their default values
33
32
 
34
- option 'styled', false
35
- option 'pass_styles' # none
36
- option 'fail_styles' # none
37
- option 'error_styles' # none
38
- option 'skip_styles' # none
39
- option 'ignore_styles' # none
33
+ option "styled", false
34
+ option "pass_styles" # none
35
+ option "fail_styles" # none
36
+ option "error_styles" # none
37
+ option "skip_styles" # none
38
+ option "ignore_styles" # none
40
39
 
41
- option 'pass_abbrev', '.'
42
- option 'fail_abbrev', 'F'
43
- option 'ignore_abbrev', 'I'
44
- option 'skip_abbrev', 'S'
45
- option 'error_abbrev', 'E'
40
+ option "pass_abbrev", "."
41
+ option "fail_abbrev", "F"
42
+ option "ignore_abbrev", "I"
43
+ option "skip_abbrev", "S"
44
+ option "error_abbrev", "E"
46
45
 
47
46
  attr_reader :config
48
47
 
@@ -92,7 +91,5 @@ module Assert
92
91
 
93
92
  def puts(*args); @output_io.puts(*args); end
94
93
  def print(*args); @output_io.print(*args); end
95
-
96
94
  end
97
-
98
95
  end
@@ -1,9 +1,7 @@
1
- require 'assert/config_helpers'
1
+ require "assert/config_helpers"
2
2
 
3
3
  module Assert
4
-
5
4
  module ViewHelpers
6
-
7
5
  def self.included(receiver)
8
6
  receiver.class_eval do
9
7
  include Assert::ConfigHelpers
@@ -13,7 +11,6 @@ module Assert
13
11
  end
14
12
 
15
13
  module ClassMethods
16
-
17
14
  def option(name, *default_vals)
18
15
  default = default_vals.size > 1 ? default_vals : default_vals.first
19
16
  define_method(name) do |*args|
@@ -23,11 +20,9 @@ module Assert
23
20
  (val = instance_variable_get("@#{name}")).nil? ? default : val
24
21
  end
25
22
  end
26
-
27
23
  end
28
24
 
29
25
  module InstanceMethods
30
-
31
26
  # show any captured output
32
27
  def captured_output(output)
33
28
  "--- stdout ---\n"\
@@ -37,21 +32,21 @@ module Assert
37
32
 
38
33
  # show any captured output
39
34
  def re_run_test_cmd(test_id)
40
- "assert -t #{test_id.gsub(Dir.pwd, '.')}"
35
+ "assert -t #{test_id.gsub(Dir.pwd, ".")}"
41
36
  end
42
37
 
43
38
  def tests_to_run_count_statement
44
- "#{self.tests_to_run_count} test#{'s' if self.tests_to_run_count != 1}"
39
+ "#{self.tests_to_run_count} test#{"s" if self.tests_to_run_count != 1}"
45
40
  end
46
41
 
47
42
  def result_count_statement
48
- "#{self.result_count} result#{'s' if self.result_count != 1}"
43
+ "#{self.result_count} result#{"s" if self.result_count != 1}"
49
44
  end
50
45
 
51
46
  # generate a comma-seperated sentence fragment given a list of items
52
47
  def to_sentence(items)
53
48
  if items.size <= 2
54
- items.join(items.size == 2 ? ' and ' : '')
49
+ items.join(items.size == 2 ? " and " : "")
55
50
  else
56
51
  [items[0..-2].join(", "), items.last].join(", and ")
57
52
  end
@@ -86,13 +81,10 @@ module Assert
86
81
  end
87
82
  self.to_sentence(summaries)
88
83
  end
89
-
90
84
  end
91
85
 
92
86
  module Ansi
93
-
94
87
  # Table of supported styles/codes (http://en.wikipedia.org/wiki/ANSI_escape_code)
95
-
96
88
  CODES = {
97
89
  :clear => 0,
98
90
  :reset => 0,
@@ -173,7 +165,7 @@ module Assert
173
165
  }
174
166
 
175
167
  def self.code_for(*style_names)
176
- style_names.map{ |n| "\e[#{CODES[n]}m" if CODES.key?(n) }.compact.join('')
168
+ style_names.map{ |n| "\e[#{CODES[n]}m" if CODES.key?(n) }.compact.join("")
177
169
  end
178
170
 
179
171
  def ansi_styled_msg(msg, result_type)
@@ -182,9 +174,6 @@ module Assert
182
174
  return msg if code.empty?
183
175
  code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
184
176
  end
185
-
186
177
  end
187
-
188
178
  end
189
-
190
179
  end
File without changes
@@ -6,54 +6,39 @@ ROOT_PATH = File.expand_path("../..", __FILE__)
6
6
  $LOAD_PATH.unshift(ROOT_PATH)
7
7
 
8
8
  # require pry for debugging (`binding.pry`)
9
- require 'pry'
10
- require 'test/support/factory'
11
-
12
- # 1.8.7 backfills
13
-
14
- # Array#sample
15
- if !(a = Array.new).respond_to?(:sample) && a.respond_to?(:choice)
16
- class Array
17
- alias_method :sample, :choice
18
- end
19
- end
20
-
21
- class Assert::Test
22
-
23
- module TestHelpers
24
-
25
- def self.included(receiver)
26
- receiver.class_eval do
27
- setup do
28
- @test_run_results = []
29
- @run_callback = proc{ |result| @test_run_results << result }
30
- end
9
+ require "pry"
10
+ require "test/support/factory"
11
+
12
+ module Assert::Test::TestHelpers
13
+ def self.included(receiver)
14
+ receiver.class_eval do
15
+ setup do
16
+ @test_run_results = []
17
+ @run_callback = proc { |result| @test_run_results << result }
31
18
  end
19
+ end
32
20
 
33
- private
34
-
35
- def test_run_callback
36
- @run_callback
37
- end
21
+ private
38
22
 
39
- def test_run_results(type = nil)
40
- return @test_run_results if type.nil?
41
- @test_run_results.select{ |r| r.type == type }
42
- end
23
+ def test_run_callback
24
+ @run_callback
25
+ end
43
26
 
44
- def test_run_result_count(type = nil)
45
- test_run_results(type).count
46
- end
27
+ def test_run_results(type = nil)
28
+ return @test_run_results if type.nil?
29
+ @test_run_results.select{ |r| r.type == type }
30
+ end
47
31
 
48
- def test_run_result_messages
49
- @test_run_results.map(&:message)
50
- end
32
+ def test_run_result_count(type = nil)
33
+ test_run_results(type).count
34
+ end
51
35
 
52
- def last_test_run_result
53
- @test_run_results.last
54
- end
36
+ def test_run_result_messages
37
+ @test_run_results.map(&:message)
55
38
  end
56
39
 
40
+ def last_test_run_result
41
+ @test_run_results.last
42
+ end
57
43
  end
58
-
59
44
  end