assert 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- assert (0.7.1)
4
+ assert (0.7.2)
5
5
  assert-view (~> 0.4)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- ansi (1.3.0)
11
- assert-view (0.4.1)
10
+ ansi (1.4.1)
11
+ assert-view (0.4.2)
12
12
  ansi (~> 1.3)
13
13
  undies (~> 1.1)
14
14
  rake (0.9.2)
@@ -115,19 +115,23 @@ module Assert
115
115
  def test(desc_or_macro, called_from=nil, first_caller=nil, &block)
116
116
  if desc_or_macro.kind_of?(Macro)
117
117
  instance_eval(&desc_or_macro)
118
- else
119
- method_name = "test: #{desc_or_macro}"
120
-
121
- # if no block given, create a test that just skips
122
- method_block = block_given? ? block : (Proc.new { skip })
123
-
118
+ elsif block_given?
124
119
  ci = Suite::ContextInfo.new(self, called_from, first_caller || caller.first)
125
- Assert.suite.tests << Test.new(method_name, ci, &method_block)
120
+ test_name = desc_or_macro
121
+
122
+ # create a test from the given code block
123
+ Assert.suite.tests << Test.new(test_name, ci, &block)
124
+ else
125
+ test_eventually(desc_or_macro, called_from, first_caller, &block)
126
126
  end
127
127
  end
128
128
 
129
129
  def test_eventually(desc_or_macro, called_from=nil, first_caller=nil, &block)
130
- test(desc_or_macro, called_from, first_caller || caller.first)
130
+ ci = Suite::ContextInfo.new(self, called_from, first_caller || caller.first)
131
+ test_name = desc_or_macro.kind_of?(Macro) ? desc_or_macro.name : desc_or_macro
132
+
133
+ # create a test from a proc that just skips
134
+ Assert.suite.tests << Test.new(test_name, ci, &(Proc.new { skip }))
131
135
  end
132
136
  alias_method :test_skip, :test_eventually
133
137
 
@@ -139,7 +143,10 @@ module Assert
139
143
  end
140
144
 
141
145
  def should_eventually(desc_or_macro, called_from=nil, first_caller=nil, &block)
142
- should(desc_or_macro, called_from, first_caller || caller.first)
146
+ if !desc_or_macro.kind_of?(Macro)
147
+ desc_or_macro = "should #{desc_or_macro}"
148
+ end
149
+ test_eventually(desc_or_macro, called_from, first_caller || caller.first)
143
150
  end
144
151
  alias_method :should_skip, :should_eventually
145
152
 
@@ -5,8 +5,11 @@ module Assert
5
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
- def initialize(*args, &block)
8
+ attr_accessor :name
9
+
10
+ def initialize(name=nil, *args, &block)
9
11
  raise ArgumentError unless block_given?
12
+ @name = name || "run this macro"
10
13
  super()
11
14
  end
12
15
 
@@ -11,7 +11,8 @@ module Assert::Macros
11
11
 
12
12
  def have_instance_method(*methods)
13
13
  called_from = (methods.last.kind_of?(Array) ? methods.pop : caller).first
14
- Assert::Macro.new do
14
+ name = "have instance methods: #{methods.map{|m| "'#{m}'"}.join(', ')}"
15
+ Assert::Macro.new(name) do
15
16
  methods.each do |method|
16
17
  should "respond to instance method ##{method}", called_from do
17
18
  assert_respond_to method, subject, "#{subject.class.name} does not have instance method ##{method}"
@@ -23,7 +24,8 @@ module Assert::Macros
23
24
 
24
25
  def have_class_method(*methods)
25
26
  called_from = (methods.last.kind_of?(Array) ? methods.pop : caller).first
26
- Assert::Macro.new do
27
+ name = "have class methods: #{methods.map{|m| "'#{m}'"}.join(', ')}"
28
+ Assert::Macro.new(name) do
27
29
  methods.each do |method|
28
30
  should "respond to class method ##{method}", called_from do
29
31
  assert_respond_to method, subject.class, "#{subject.class.name} does not have class method ##{method}"
@@ -10,7 +10,7 @@ module Assert
10
10
 
11
11
  class << self
12
12
 
13
- USER_TEST_HELPER = "~/.assert/options"
13
+ USER_TEST_HELPER = "./.assert/options"
14
14
 
15
15
  # assume the test dir path is ./test and look for helpers in ./test/helper.rb
16
16
  def package_test_dir
@@ -33,26 +33,24 @@ module Assert
33
33
  private
34
34
 
35
35
  def require_user_test_helper
36
- begin
37
- if ENV['HOME']
38
- require File.expand_path(USER_TEST_HELPER)
39
- end
40
- rescue LoadError => err
41
- # do nothing
36
+ if ENV['HOME']
37
+ safe_require File.expand_path(USER_TEST_HELPER, ENV['HOME'])
42
38
  end
43
39
  end
44
40
 
45
41
  # require the package's test/helper file if it exists
46
42
  def require_package_test_helper(root_path)
47
- begin
48
- require package_helper_file(root_path)
49
- rescue LoadError => err
50
- # do nothing
51
- end
43
+ safe_require package_helper_file(root_path)
52
44
  end
53
45
 
54
46
  def package_helper_file(root_path)
55
- File.join(root_path, package_test_dir, package_helper_name + '.rb')
47
+ File.join(root_path, package_test_dir, package_helper_name)
48
+ end
49
+
50
+ def safe_require(helper_file)
51
+ if File.exists?(helper_file+".rb")
52
+ require helper_file
53
+ end
56
54
  end
57
55
 
58
56
  # this method inspects the caller info and finds the caller's root path
@@ -115,7 +115,7 @@ module Assert
115
115
 
116
116
  def name_from_context(name)
117
117
  [ self.context_class.description,
118
- name.gsub(/^test:\s+should/, "should")
118
+ name
119
119
  ].compact.reject{|p| p.empty?}.join(" ")
120
120
  end
121
121
 
@@ -1,3 +1,3 @@
1
1
  module Assert
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -301,19 +301,50 @@ class Assert::Context
301
301
  setup do
302
302
  @test_count_before = Assert.suite.tests.size
303
303
 
304
- @should_desc = "be true"
305
- @should_block = ::Proc.new{ assert(true) }
306
- @method_name = "test: #{@should_desc}"
304
+ @test_desc = "be true"
305
+ @test_block = ::Proc.new{ assert(true) }
306
+ @test_name = @test_desc
307
307
 
308
- d, b = @should_desc, @should_block
308
+ d, b = @test_desc, @test_block
309
309
  @context_class = Factory.context_class { test(d, &b) }
310
310
  @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
311
311
  end
312
312
  subject{ @context }
313
313
 
314
- should "define a test method named after the should desc" do
314
+ should "build a test with a given desc and code block" do
315
315
  assert_equal @test_count_before+1, Assert.suite.tests.size
316
- assert_equal @should_block, Assert.suite.tests.last.code
316
+ built_test = Assert.suite.tests.last
317
+
318
+ assert_kind_of Assert::Test, built_test
319
+ assert_equal @test_name, built_test.name
320
+
321
+ assert_equal @test_block, built_test.code
322
+ end
323
+
324
+ end
325
+
326
+ class TestMacroTest < TestMethTest
327
+ desc "on a macro"
328
+ setup do
329
+ @test_count_before = Assert.suite.tests.size
330
+ d, b = @test_desc, @test_block
331
+ m = Assert::Macro.new do
332
+ test(d, &b)
333
+ test(d, &b)
334
+ end
335
+ @context_class = Factory.context_class { test(m) }
336
+ @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
337
+ end
338
+ subject{ @context }
339
+
340
+ should "build tests from the macro" do
341
+ assert_equal @test_count_before+2, Assert.suite.tests.size
342
+ built_test = Assert.suite.tests.last
343
+
344
+ assert_kind_of Assert::Test, built_test
345
+ assert_equal @test_name, built_test.name
346
+
347
+ assert_equal @test_block, built_test.code
317
348
  end
318
349
 
319
350
  end
@@ -321,13 +352,15 @@ class Assert::Context
321
352
  class NoBlockTestMethTest < TestMethTest
322
353
  desc "called with no block"
323
354
  setup do
324
- d = @should_desc
355
+ @test_count_before = Assert.suite.tests.size
356
+ d = @test_desc
325
357
  @context_class = Factory.context_class { test(d) }
326
358
  @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
327
359
  end
328
360
  subject{ @context }
329
361
 
330
- should "define a test method named after the should desc that raises a test skipped" do
362
+ should "build a test that skips" do
363
+ assert_equal @test_count_before+1, Assert.suite.tests.size
331
364
  assert_raises(Assert::Result::TestSkipped) do
332
365
  subject.instance_eval(&Assert.suite.tests.last.code)
333
366
  end
@@ -336,9 +369,10 @@ class Assert::Context
336
369
  end
337
370
 
338
371
  class TestEventuallyTest < TestMethTest
339
- desc "test_eventually method"
372
+ desc "called with '_eventually'"
340
373
  setup do
341
- d, b = @should_desc, @should_block
374
+ @test_count_before = Assert.suite.tests.size
375
+ d, b = @test_desc, @test_block
342
376
  @context_class = Factory.context_class do
343
377
  test_eventually(d, &b)
344
378
  end
@@ -346,7 +380,31 @@ class Assert::Context
346
380
  end
347
381
  subject{ @context }
348
382
 
349
- should "define a test method named after the should desc that raises a test skipped" do
383
+ should "build a test that skips" do
384
+ assert_equal @test_count_before+1, Assert.suite.tests.size
385
+ assert_raises(Assert::Result::TestSkipped) do
386
+ subject.instance_eval(&Assert.suite.tests.last.code)
387
+ end
388
+ end
389
+
390
+ end
391
+
392
+ class TestEventuallyMacroTest < TestEventuallyTest
393
+ desc "on a macro"
394
+ setup do
395
+ @test_count_before = Assert.suite.tests.size
396
+ d, b = @test_desc, @test_block
397
+ m = Assert::Macro.new do
398
+ test(d, &b)
399
+ test(d, &b)
400
+ end
401
+ @context_class = Factory.context_class { test_eventually(m) }
402
+ @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
403
+ end
404
+ subject{ @context }
405
+
406
+ should "build a test that skips" do
407
+ assert_equal @test_count_before+1, Assert.suite.tests.size
350
408
  assert_raises(Assert::Result::TestSkipped) do
351
409
  subject.instance_eval(&Assert.suite.tests.last.code)
352
410
  end
@@ -363,7 +421,7 @@ class Assert::Context
363
421
 
364
422
  @should_desc = "be true"
365
423
  @should_block = ::Proc.new{ assert(true) }
366
- @method_name = "test: should #{@should_desc}"
424
+ @test_name = "should #{@should_desc}"
367
425
 
368
426
  d, b = @should_desc, @should_block
369
427
  @context_class = Factory.context_class { should(d, &b) }
@@ -371,9 +429,40 @@ class Assert::Context
371
429
  end
372
430
  subject{ @context }
373
431
 
374
- should "define a test method named after the should desc" do
432
+ should "build a test with a given should desc and code block" do
375
433
  assert_equal @test_count_before+1, Assert.suite.tests.size
376
- assert_equal @should_block, Assert.suite.tests.last.code
434
+ built_test = Assert.suite.tests.last
435
+
436
+ assert_kind_of Assert::Test, built_test
437
+ assert_equal @test_name, built_test.name
438
+
439
+ assert_equal @should_block, built_test.code
440
+ end
441
+
442
+ end
443
+
444
+ class ShouldMacroTest < ShouldTest
445
+ desc "on a macro"
446
+ setup do
447
+ @test_count_before = Assert.suite.tests.size
448
+ d, b = @should_desc, @should_block
449
+ m = Assert::Macro.new do
450
+ should(d, &b)
451
+ should(d, &b)
452
+ end
453
+ @context_class = Factory.context_class { should m }
454
+ @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
455
+ end
456
+ subject{ @context }
457
+
458
+ should "build tests from the macro" do
459
+ assert_equal @test_count_before+2, Assert.suite.tests.size
460
+ built_test = Assert.suite.tests.last
461
+
462
+ assert_kind_of Assert::Test, built_test
463
+ assert_equal @test_name, built_test.name
464
+
465
+ assert_equal @should_block, built_test.code
377
466
  end
378
467
 
379
468
  end
@@ -381,13 +470,15 @@ class Assert::Context
381
470
  class NoBlockShouldTest < ShouldTest
382
471
  desc "called with no block"
383
472
  setup do
473
+ @test_count_before = Assert.suite.tests.size
384
474
  d = @should_desc
385
475
  @context_class = Factory.context_class { should(d) }
386
476
  @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
387
477
  end
388
478
  subject{ @context }
389
479
 
390
- should "define a test method named after the should desc that raises a test skipped" do
480
+ should "build a test that skips" do
481
+ assert_equal @test_count_before+1, Assert.suite.tests.size
391
482
  assert_raises(Assert::Result::TestSkipped) do
392
483
  subject.instance_eval(&Assert.suite.tests.last.code)
393
484
  end
@@ -396,15 +487,40 @@ class Assert::Context
396
487
  end
397
488
 
398
489
  class ShouldEventuallyTest < ShouldTest
399
- desc "should_eventually method"
490
+ desc "called with '_eventually'"
400
491
  setup do
492
+ @test_count_before = Assert.suite.tests.size
401
493
  d, b = @should_desc, @should_block
402
494
  @context_class = Factory.context_class { should_eventually(d, &b) }
403
495
  @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
404
496
  end
405
497
  subject{ @context }
406
498
 
407
- should "define a test method named after the should desc that raises a test skipped" do
499
+ should "build a test that skips" do
500
+ assert_equal @test_count_before+1, Assert.suite.tests.size
501
+ assert_raises(Assert::Result::TestSkipped) do
502
+ subject.instance_eval(&Assert.suite.tests.last.code)
503
+ end
504
+ end
505
+
506
+ end
507
+
508
+ class ShouldEventuallyMacroTest < ShouldEventuallyTest
509
+ desc "on a macro"
510
+ setup do
511
+ @test_count_before = Assert.suite.tests.size
512
+ d, b = @should_desc, @should_block
513
+ m = Assert::Macro.new do
514
+ should(d, &b)
515
+ should(d, &b)
516
+ end
517
+ @context_class = Factory.context_class { should_eventually(m) }
518
+ @context = @context_class.new(Factory.test("something", Factory.context_info(@context_class)))
519
+ end
520
+ subject{ @context }
521
+
522
+ should "build a test that skips" do
523
+ assert_equal @test_count_before+1, Assert.suite.tests.size
408
524
  assert_raises(Assert::Result::TestSkipped) do
409
525
  subject.instance_eval(&Assert.suite.tests.last.code)
410
526
  end
@@ -6,7 +6,21 @@ class Assert::Macro
6
6
 
7
7
  class BaseTest < Assert::Context
8
8
  desc "a macro"
9
- subject { Assert::Macro.new {} }
9
+ setup { @macro = Assert::Macro.new {} }
10
+ subject { @macro }
11
+
12
+ should "have an accessor for its (optional) name" do
13
+ assert_respond_to :name, subject
14
+ assert_respond_to :name=, subject
15
+ end
16
+
17
+ should "default its name if no given" do
18
+ assert_equal "run this macro", (Assert::Macro.new {}).name
19
+ end
20
+
21
+ should "initialize with a given name" do
22
+ assert_equal "test", (Assert::Macro.new("test") {}).name
23
+ end
10
24
 
11
25
  should "be a Proc" do
12
26
  assert_kind_of ::Proc, subject
@@ -17,6 +31,7 @@ class Assert::Macro
17
31
  Assert::Macro.new
18
32
  end
19
33
  end
34
+
20
35
  end
21
36
 
22
37
  class InstanceMethodsTest < Assert::Context
@@ -5,7 +5,7 @@ class Assert::Test
5
5
  class BasicTest < Assert::Context
6
6
  desc "Assert test"
7
7
  setup do
8
- test_name = "test: should do something amazing"
8
+ test_name = "should do something amazing"
9
9
  @test_code = lambda{ assert(true) }
10
10
  context_desc = "context class"
11
11
  @context_class = Factory.context_class do
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: 1
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 1
10
- version: 0.7.1
9
+ - 2
10
+ version: 0.7.2
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: 2011-10-13 00:00:00 Z
19
+ date: 2011-11-29 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  type: :development
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  requirements: []
168
168
 
169
169
  rubyforge_project:
170
- rubygems_version: 1.8.10
170
+ rubygems_version: 1.8.11
171
171
  signing_key:
172
172
  specification_version: 3
173
173
  summary: Test::Unit style testing framework, just better than Test::Unit.