assert 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/README.md +8 -8
  2. data/lib/assert.rb +9 -62
  3. data/lib/assert/assert_runner.rb +15 -30
  4. data/lib/assert/assertions.rb +105 -41
  5. data/lib/assert/cli.rb +1 -1
  6. data/lib/assert/config.rb +56 -0
  7. data/lib/assert/context.rb +44 -150
  8. data/lib/assert/context/setup_dsl.rb +70 -0
  9. data/lib/assert/context/subject_dsl.rb +39 -0
  10. data/lib/assert/context/suite_dsl.rb +20 -0
  11. data/lib/assert/context/test_dsl.rb +51 -0
  12. data/lib/assert/runner.rb +8 -2
  13. data/lib/assert/suite.rb +33 -12
  14. data/lib/assert/test.rb +11 -8
  15. data/lib/assert/utils.rb +23 -11
  16. data/lib/assert/version.rb +1 -1
  17. data/lib/assert/view.rb +9 -7
  18. data/lib/assert/view/base.rb +26 -4
  19. data/lib/assert/view/default_view.rb +1 -1
  20. data/lib/assert/view/helpers/ansi_styles.rb +1 -1
  21. data/lib/assert/view/helpers/common.rb +16 -6
  22. data/test/helper.rb +1 -94
  23. data/test/support/factory.rb +70 -0
  24. data/test/system/running_tests.rb +55 -28
  25. data/test/unit/assert_tests.rb +6 -33
  26. data/test/unit/assertions/assert_block_tests.rb +3 -3
  27. data/test/unit/assertions/assert_empty_tests.rb +6 -4
  28. data/test/unit/assertions/assert_equal_tests.rb +19 -22
  29. data/test/unit/assertions/assert_file_exists_tests.rb +6 -4
  30. data/test/unit/assertions/assert_includes_tests.rb +8 -4
  31. data/test/unit/assertions/assert_instance_of_tests.rb +8 -6
  32. data/test/unit/assertions/assert_kind_of_tests.rb +8 -5
  33. data/test/unit/assertions/assert_match_tests.rb +8 -4
  34. data/test/unit/assertions/assert_nil_tests.rb +6 -4
  35. data/test/unit/assertions/assert_raises_tests.rb +2 -2
  36. data/test/unit/assertions/assert_respond_to_tests.rb +7 -5
  37. data/test/unit/assertions/assert_same_tests.rb +75 -6
  38. data/test/unit/assertions/assert_true_false_tests.rb +116 -0
  39. data/test/unit/assertions_tests.rb +7 -5
  40. data/test/unit/config_tests.rb +58 -0
  41. data/test/unit/context/{setup_teardown_singleton_tests.rb → setup_dsl_tests.rb} +17 -19
  42. data/test/unit/context/subject_dsl_tests.rb +78 -0
  43. data/test/unit/context/suite_dsl_tests.rb +47 -0
  44. data/test/unit/context/{test_should_singleton_tests.rb → test_dsl_tests.rb} +33 -34
  45. data/test/unit/context_tests.rb +19 -15
  46. data/test/unit/runner_tests.rb +9 -3
  47. data/test/unit/suite_tests.rb +20 -23
  48. data/test/unit/test_tests.rb +22 -14
  49. data/test/unit/utils_tests.rb +15 -21
  50. data/test/unit/view_tests.rb +12 -5
  51. metadata +23 -10
  52. data/test/unit/context/basic_singleton_tests.rb +0 -86
@@ -1,22 +1,21 @@
1
1
  require 'assert'
2
2
  require 'assert/test'
3
3
 
4
+ require 'assert/config'
5
+
4
6
  class Assert::Test
5
7
 
6
8
  class BasicTests < Assert::Context
7
9
  desc "a test obj"
8
10
  setup do
9
11
  @test_code = lambda{ assert(true) }
10
- @context_class = Factory.context_class{ desc "context class" }
12
+ @context_class = Factory.modes_off_context_class{ desc "context class" }
11
13
  @context_info = Factory.context_info(@context_class)
12
- @test = Factory.test("should do something amazing", @context_info, @test_code)
13
- end
14
- teardown do
15
- TEST_ASSERT_SUITE.tests.clear
14
+ @test = Factory.test("should do something amazing", @context_info, :code => @test_code)
16
15
  end
17
16
  subject{ @test }
18
17
 
19
- should have_readers :name, :code, :context_info
18
+ should have_readers :name, :context_info, :config, :code
20
19
  should have_accessors :results, :output
21
20
  should have_imeths :run, :result_count, :context_class
22
21
  should have_imeths *Assert::Result.types.keys.collect{ |k| "#{k}_results" }
@@ -26,9 +25,22 @@ class Assert::Test
26
25
  assert_equal exp_name, subject.name
27
26
  end
28
27
 
29
- should "know it's context class and code" do
28
+ should "know it's context class" do
30
29
  assert_equal @context_class, subject.context_class
30
+ end
31
+
32
+ should "know its config" do
33
+ cust_config = Assert::Config.new
34
+ assert_equal cust_config, Factory.test(cust_config).config
35
+ end
36
+
37
+ should "get its code from any passed opt, falling back on any given block" do
31
38
  assert_equal @test_code, subject.code
39
+
40
+ given_block = Proc.new{ assert(false) }
41
+ assert_equal given_block, Factory.test(&given_block).code
42
+
43
+ assert_kind_of Proc, Factory.test.code
32
44
  end
33
45
 
34
46
  should "have zero results before running" do
@@ -238,15 +250,11 @@ class Assert::Test
238
250
  class CaptureOutTests < BasicTests
239
251
  desc "when capturing std out"
240
252
  setup do
241
- @test = Factory.test("stdout") do
253
+ @capture_config = Assert::Config.new(:capture_output => true)
254
+ @test = Factory.test("stdout", @capture_config) do
242
255
  puts "std out from the test"
243
256
  assert true
244
257
  end
245
- @orig_capture = Assert.config.capture_output
246
- Assert.config.capture_output true
247
- end
248
- teardown do
249
- Assert.config.capture_output @orig_capture
250
258
  end
251
259
 
252
260
  should "capture any io from the test" do
@@ -259,7 +267,7 @@ class Assert::Test
259
267
  class FullCaptureOutTests < CaptureOutTests
260
268
  desc "across setup, teardown, and meth calls"
261
269
  setup do
262
- @test = Factory.test("fullstdouttest") do
270
+ @test = Factory.test("fullstdouttest", @capture_config) do
263
271
  puts "std out from the test"
264
272
  assert a_method_an_assert_calls
265
273
  end
@@ -2,6 +2,7 @@ require 'assert'
2
2
  require 'assert/utils'
3
3
 
4
4
  require 'tempfile'
5
+ require 'assert/config'
5
6
 
6
7
  module Assert::Utils
7
8
 
@@ -15,41 +16,34 @@ module Assert::Utils
15
16
  should have_imeths :show, :show_for_diff
16
17
  should have_imeths :tempfile
17
18
  should have_imeths :stdlib_pp_proc, :default_use_diff_proc, :syscmd_diff_proc
19
+ should have_imeths :git_changed_proc
18
20
 
19
21
  end
20
22
 
21
23
  class ShowTests < UnitTests
22
24
  desc "`show`"
23
25
  setup do
24
- @orig_pp_objs = Assert.config.pp_objects
25
- @orig_pp_proc = Assert.config.pp_proc
26
- @new_pp_proc = Proc.new{ |input| 'herp derp' }
27
- end
28
- teardown do
29
- Assert.config.pp_proc(@orig_pp_proc)
30
- Assert.config.pp_objects(@orig_pp_objs)
26
+ @pp_config = Assert::Config.new({
27
+ :pp_objects => true,
28
+ :pp_proc => Proc.new{ |input| 'herp derp' }
29
+ })
31
30
  end
32
31
 
33
32
  should "use `inspect` to show objs when `pp_objects` setting is false" do
34
- Assert.config.pp_objects(false)
35
-
36
33
  @objs.each do |obj|
37
- assert_equal obj.inspect, subject.show(obj)
34
+ assert_equal obj.inspect, subject.show(obj, Factory.modes_off_config)
38
35
  end
39
36
  end
40
37
 
41
38
  should "use `pp_proc` to show objs when `pp_objects` setting is true" do
42
- Assert.config.pp_objects(true)
43
- Assert.config.pp_proc(@new_pp_proc)
44
-
45
39
  @objs.each do |obj|
46
- assert_equal @new_pp_proc.call(obj), subject.show(obj)
40
+ assert_equal @pp_config.pp_proc.call(obj), subject.show(obj, @pp_config)
47
41
  end
48
42
  end
49
43
 
50
44
  end
51
45
 
52
- class ShowForDiffTests < UnitTests
46
+ class ShowForDiffTests < ShowTests
53
47
  desc "`show_for_diff`"
54
48
  setup do
55
49
  @w_newlines = { :string => "herp derp, derp herp\nherpderpedia" }
@@ -58,12 +52,12 @@ module Assert::Utils
58
52
 
59
53
  should "call show, escaping newlines" do
60
54
  exp_out = "{:string=>\"herp derp, derp herp\nherpderpedia\"}"
61
- assert_equal exp_out, subject.show_for_diff(@w_newlines)
55
+ assert_equal exp_out, subject.show_for_diff(@w_newlines, Factory.modes_off_config)
62
56
  end
63
57
 
64
58
  should "make any obj ids generic" do
65
59
  exp_out = "#<struct #<Class:0xXXXXXX> a=\"aye\", b=\"bee\">"
66
- assert_equal exp_out, subject.show_for_diff(@w_obj_id)
60
+ assert_equal exp_out, subject.show_for_diff(@w_obj_id, Factory.modes_off_config)
67
61
  end
68
62
 
69
63
  end
@@ -88,12 +82,12 @@ module Assert::Utils
88
82
  desc "`stdlib_pp_proc`"
89
83
 
90
84
  should "build a pp proc that uses stdlib `PP.pp` to pretty print objects" do
91
- exp_obj_pps = @objs.map{ |o| "\n#{PP.pp(o, '', 79).strip}\n" }
85
+ exp_obj_pps = @objs.map{ |o| PP.pp(o, '', 79).strip }
92
86
  act_obj_pps = @objs.map{ |o| subject.stdlib_pp_proc.call(o) }
93
87
  assert_equal exp_obj_pps, act_obj_pps
94
88
 
95
89
  cust_width = 1
96
- exp_obj_pps = @objs.map{ |o| "\n#{PP.pp(o, '', cust_width).strip}\n" }
90
+ exp_obj_pps = @objs.map{ |o| PP.pp(o, '', cust_width).strip }
97
91
  act_obj_pps = @objs.map{ |o| subject.stdlib_pp_proc(cust_width).call(o) }
98
92
  assert_equal exp_obj_pps, act_obj_pps
99
93
  end
@@ -131,7 +125,7 @@ module Assert::Utils
131
125
  end
132
126
 
133
127
  should "use the diff syscmd to output the diff between the exp/act show output" do
134
- exp_diff_out = `diff --unified=-1 #{@diff_a_file} #{@diff_b_file}`.tap do |out|
128
+ exp_diff_out = `diff --unified=-1 #{@diff_a_file} #{@diff_b_file}`.strip.tap do |out|
135
129
  out.sub!(/^\-\-\- .+/, "--- expected")
136
130
  out.sub!(/^\+\+\+ .+/, "+++ actual")
137
131
  end
@@ -141,7 +135,7 @@ module Assert::Utils
141
135
 
142
136
  should "allow you to specify a custom syscmd" do
143
137
  cust_syscmd = 'diff'
144
- exp_diff_out = `#{cust_syscmd} #{@diff_a_file} #{@diff_b_file}`.tap do |out|
138
+ exp_diff_out = `#{cust_syscmd} #{@diff_a_file} #{@diff_b_file}`.strip.tap do |out|
145
139
  out.sub!(/^\-\-\- .+/, "--- expected")
146
140
  out.sub!(/^\+\+\+ .+/, "+++ actual")
147
141
  end
@@ -3,22 +3,25 @@ require 'assert/suite'
3
3
  require 'assert/view/base'
4
4
  require 'stringio'
5
5
 
6
- module Assert::View
6
+ class Assert::View::Base
7
7
 
8
8
  class UnitTests < Assert::Context
9
- desc "the base view"
9
+ desc "Assert::View::Base"
10
10
  setup do
11
- @view = Assert::View::Base.new(StringIO.new("", "w+"), Assert::Suite.new)
11
+ @io = StringIO.new("", "w+")
12
+ @config = Factory.modes_off_config
13
+ @view = Assert::View::Base.new(@io, @config, @config.suite)
12
14
  end
13
15
  subject{ @view }
14
16
 
15
17
  # accessors, base methods
16
- should have_imeths :view, :suite, :fire
18
+ should have_imeths :is_tty?, :view, :config, :suite, :fire
17
19
  should have_imeths :before_load, :after_load, :on_start, :on_finish
18
20
  should have_imeths :before_test, :after_test, :on_result
19
21
 
20
22
  # common methods
21
- should have_imeths :run_time, :runner_seed, :count, :tests?, :all_pass?
23
+ should have_imeths :runner_seed, :count, :tests?, :all_pass?
24
+ should have_imeths :run_time, :test_rate, :result_rate
22
25
  should have_imeths :suite_contexts, :ordered_suite_contexts
23
26
  should have_imeths :suite_files, :ordered_suite_files
24
27
  should have_imeths :result_details_for, :show_result_details?
@@ -35,6 +38,10 @@ module Assert::View
35
38
  assert_equal 'E', subject.error_abbrev
36
39
  end
37
40
 
41
+ should "know if it is a tty" do
42
+ assert_equal !!@io.isatty, subject.is_tty?
43
+ end
44
+
38
45
  end
39
46
 
40
47
  class HandlerTests < Assert::Context
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 2.4.0
10
+ version: 2.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-11-20 00:00:00 Z
19
+ date: 2014-01-02 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: ansi
@@ -56,7 +56,12 @@ files:
56
56
  - lib/assert/assert_runner.rb
57
57
  - lib/assert/assertions.rb
58
58
  - lib/assert/cli.rb
59
+ - lib/assert/config.rb
59
60
  - lib/assert/context.rb
61
+ - lib/assert/context/setup_dsl.rb
62
+ - lib/assert/context/subject_dsl.rb
63
+ - lib/assert/context/suite_dsl.rb
64
+ - lib/assert/context/test_dsl.rb
60
65
  - lib/assert/macro.rb
61
66
  - lib/assert/macros/methods.rb
62
67
  - lib/assert/result.rb
@@ -74,6 +79,7 @@ files:
74
79
  - test/helper.rb
75
80
  - test/support/diff_a.txt
76
81
  - test/support/diff_b.txt
82
+ - test/support/factory.rb
77
83
  - test/support/inherited_stuff.rb
78
84
  - test/system/running_tests.rb
79
85
  - test/unit/assert_tests.rb
@@ -89,10 +95,13 @@ files:
89
95
  - test/unit/assertions/assert_raises_tests.rb
90
96
  - test/unit/assertions/assert_respond_to_tests.rb
91
97
  - test/unit/assertions/assert_same_tests.rb
98
+ - test/unit/assertions/assert_true_false_tests.rb
92
99
  - test/unit/assertions_tests.rb
93
- - test/unit/context/basic_singleton_tests.rb
94
- - test/unit/context/setup_teardown_singleton_tests.rb
95
- - test/unit/context/test_should_singleton_tests.rb
100
+ - test/unit/config_tests.rb
101
+ - test/unit/context/setup_dsl_tests.rb
102
+ - test/unit/context/subject_dsl_tests.rb
103
+ - test/unit/context/suite_dsl_tests.rb
104
+ - test/unit/context/test_dsl_tests.rb
96
105
  - test/unit/context_tests.rb
97
106
  - test/unit/macro_tests.rb
98
107
  - test/unit/result_tests.rb
@@ -139,6 +148,7 @@ test_files:
139
148
  - test/helper.rb
140
149
  - test/support/diff_a.txt
141
150
  - test/support/diff_b.txt
151
+ - test/support/factory.rb
142
152
  - test/support/inherited_stuff.rb
143
153
  - test/system/running_tests.rb
144
154
  - test/unit/assert_tests.rb
@@ -154,10 +164,13 @@ test_files:
154
164
  - test/unit/assertions/assert_raises_tests.rb
155
165
  - test/unit/assertions/assert_respond_to_tests.rb
156
166
  - test/unit/assertions/assert_same_tests.rb
167
+ - test/unit/assertions/assert_true_false_tests.rb
157
168
  - test/unit/assertions_tests.rb
158
- - test/unit/context/basic_singleton_tests.rb
159
- - test/unit/context/setup_teardown_singleton_tests.rb
160
- - test/unit/context/test_should_singleton_tests.rb
169
+ - test/unit/config_tests.rb
170
+ - test/unit/context/setup_dsl_tests.rb
171
+ - test/unit/context/subject_dsl_tests.rb
172
+ - test/unit/context/suite_dsl_tests.rb
173
+ - test/unit/context/test_dsl_tests.rb
161
174
  - test/unit/context_tests.rb
162
175
  - test/unit/macro_tests.rb
163
176
  - test/unit/result_tests.rb
@@ -1,86 +0,0 @@
1
- require 'assert'
2
- require 'assert/context'
3
-
4
- class Assert::Context
5
-
6
- # `ContextSingletonTests` defined in `test/helper.rb`
7
- class BasicSingletonTests < ContextSingletonTests
8
- should have_instance_methods :setup_once, :before_once, :startup
9
- should have_instance_methods :teardown_once, :after_once, :shutdown
10
- should have_instance_methods :setup, :before, :setups
11
- should have_instance_methods :teardown, :after, :teardowns
12
- should have_instance_methods :description, :desc, :describe, :subject
13
- should have_instance_methods :test, :test_eventually, :test_skip
14
- should have_instance_methods :should, :should_eventually, :should_skip
15
-
16
- end
17
-
18
- class DescriptionsTests < BasicSingletonTests
19
- desc "`descriptions` method"
20
- setup do
21
- descs = @descs = [ "something amazing", "it really is" ]
22
- @context_class = Factory.context_class do
23
- descs.each{ |text| desc text }
24
- end
25
- end
26
-
27
- should "return a collection containing any descriptions defined on the class" do
28
- context_descs = subject.send :descriptions
29
- assert_equal @descs, context_descs
30
- end
31
-
32
- end
33
-
34
- class DescriptionTests < BasicSingletonTests
35
- desc "`description` method"
36
- setup do
37
- parent_text = @parent_desc = "parent description"
38
- @parent_class = Factory.context_class do
39
- desc parent_text
40
- end
41
- text = @desc = "and the description for this context"
42
- @context_class = Factory.context_class(@parent_class) do
43
- desc text
44
- end
45
- end
46
-
47
- should "return a string of all the inherited descriptions" do
48
- exp_desc = "parent description and the description for this context"
49
- assert_equal exp_desc, @context_class.description
50
- end
51
-
52
- end
53
-
54
- class SubjectFromLocalTests < BasicSingletonTests
55
- desc "subject method using local context"
56
- setup do
57
- subject_block = @subject_block = ::Proc.new{ @something }
58
- @context_class = Factory.context_class do
59
- subject(&subject_block)
60
- end
61
- end
62
- subject{ @subject_block }
63
-
64
- should "set the subject block on the context class" do
65
- assert_equal @context_class.subject, subject
66
- end
67
-
68
- end
69
-
70
- class SubjectFromParentTests < BasicSingletonTests
71
- desc "subject method using parent context"
72
- setup do
73
- parent_block = @parent_block = ::Proc.new{ @something }
74
- @parent_class = Factory.context_class do
75
- subject(&parent_block)
76
- end
77
- @context_class = Factory.context_class(@parent_class)
78
- end
79
- subject{ @parent_block }
80
-
81
- should "default to it's parents subject block" do
82
- assert_equal @context_class.subject, subject
83
- end
84
- end
85
-
86
- end