renvy 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/HISTORY.md +6 -0
  2. data/README.md +8 -2
  3. data/lib/renvy.rb +18 -13
  4. data/test/renvy_test.rb +27 -4
  5. metadata +1 -1
data/HISTORY.md CHANGED
@@ -1,3 +1,9 @@
1
+ v0.2.2 - May 17, 2011
2
+ ---------------------
3
+
4
+ ### Added:
5
+ * Messages (#blaming and #messaging)
6
+
1
7
  v0.2.1 - May 17, 2011
2
8
  ---------------------
3
9
 
data/README.md CHANGED
@@ -23,21 +23,27 @@ obj.should.nil # => assert_nil obj
23
23
  obj.should.be.nil # => assert_nil obj
24
24
  obj.should.be.a.nil # => assert_nil obj
25
25
 
26
- # You can also use should_not:
26
+ # You can also use should_not, or should.not:
27
27
  obj.should_not == 3
28
- obj.should_not.be.nil?
28
+ obj.should.not == 3
29
+ obj.should_not.be.nil
29
30
 
30
31
  # Anything else will pass through with a ?:
31
32
  obj.should.be.good_looking # => assert obj.good_looking?
32
33
 
33
34
  should.raise(Error) { lol }
34
35
  should_not.raise { puts "hi" }
36
+
37
+ # You may add messages to your asserts with #blaming or #messaging.
38
+ (2 + 2).should.blaming("weird math") == 4
35
39
  ```
36
40
 
37
41
  ## Wrapped assertions
38
42
 
39
43
  These are based from Test::Spec.
40
44
 
45
+ | Test::Unit | REnvy |
46
+ |-----------------------------|---------------------------------------|
41
47
  | assert_equal | should.equal, should == |
42
48
  | assert_not_equal | should.not.equal, should.not == |
43
49
  | assert_same | should.be |
@@ -23,7 +23,7 @@ require 'test/unit'
23
23
  # should_not.raise { puts "hi" }
24
24
  #
25
25
  module REnvy
26
- VERSION = "0.2.1"
26
+ VERSION = "0.2.2"
27
27
 
28
28
  def self.version
29
29
  VERSION
@@ -31,6 +31,7 @@ module REnvy
31
31
 
32
32
  class Should
33
33
  attr_reader :left
34
+ attr_reader :msg
34
35
 
35
36
  def self.init(test) # :nodoc:
36
37
  @@test = test
@@ -46,7 +47,7 @@ module REnvy
46
47
  @neg = neg
47
48
  end
48
49
 
49
- def be() self; end
50
+ def be(right=nil) self.same(right) if right; self; end
50
51
  def a() self; end
51
52
  def an() self; end
52
53
 
@@ -55,6 +56,9 @@ module REnvy
55
56
  def test() @@test; end
56
57
  def not() @neg = true; self; end
57
58
 
59
+ def blaming(msg); @msg = msg; self; end
60
+ def messaging(msg); @msg = msg; self; end
61
+
58
62
  def ==(right) assert_or_refute :equal, right, left; end
59
63
  def !=(right) assert_or_refute_not :equal, right, left; end
60
64
  def =~(right) assert_or_refute :match, right, left; end
@@ -78,36 +82,37 @@ module REnvy
78
82
  def in_epsilon(right, d=0.001) assert_or_refute :in_epsilon, right, left, d; end
79
83
 
80
84
  def assert_or_refute(what, *args, &blk)
81
- test.send (positive? ? :"assert_#{what}" : :"refute_#{what}"), *args, &blk
85
+ test.send (positive? ? :"assert_#{what}" : :"refute_#{what}"), *args, msg, &blk
82
86
  end
83
87
 
84
88
  def assert_or_refute_not(what, *args)
85
- test.send (negative? ? :"assert_#{what}" : :"refute_#{what}"), *args
89
+ test.send (negative? ? :"assert_#{what}" : :"refute_#{what}"), *args, msg
86
90
  end
87
91
 
88
92
  def throw(what=nil, &blk)
89
93
  if positive?
90
- test.send :assert_throws, what, &blk
94
+ test.send :assert_throws, what, msg, &blk
91
95
  else
92
- test.send :assert_nothing_thrown, &blk
96
+ test.send :assert_nothing_thrown, msg, &blk
93
97
  end
94
98
  end
95
99
 
96
100
  def raise(ex=StandardError, &blk)
97
101
  if positive?
98
- test.send :assert_raises, ex, &blk
102
+ test.send :assert_raises, ex, msg, &blk
99
103
  else
100
- test.send :assert_nothing_raised, &blk
104
+ test.send :assert_nothing_raised, msg, &blk
101
105
  end
102
106
  end
103
107
 
104
108
  def method_missing(meth, *args, &blk)
105
109
  result = left.send(:"#{meth}?", *args, &blk)
106
- if positive?
107
- test.send :assert, result
108
- else
109
- test.send :assert, ! result
110
- end
110
+ method = positive? ? :assert : :refute
111
+
112
+ args = [result]
113
+ args << msg if msg
114
+
115
+ test.send method, *args
111
116
  end
112
117
  end
113
118
  end
@@ -54,8 +54,9 @@ class REnvyTest < Test::Unit::TestCase
54
54
 
55
55
  a = Object.new
56
56
  b = a
57
- a.should.be.equal?(b)
58
- a.should_not.be.equal?(Object.new)
57
+ a.should.be.equal(b)
58
+ a.should.be(b)
59
+ a.should_not.be.equal(Object.new)
59
60
 
60
61
  Math::PI.should.be.close(22.0/7, 0.1)
61
62
 
@@ -66,16 +67,38 @@ class REnvyTest < Test::Unit::TestCase
66
67
  Foo.new.should.get_true
67
68
  end
68
69
 
70
+ def test_should_be
71
+ a = Object.new
72
+ b = a
73
+
74
+ expects(:assert_same).with(a, b, nil)
75
+ a.should.be(b)
76
+ end
77
+
69
78
  def test_include
70
- expects(:assert_includes).with([], 2)
79
+ expects(:assert_includes).with([], 2, nil)
71
80
  [].should.include 2
72
81
  end
73
82
 
74
83
  def test_include_not
75
- expects(:refute_includes).with([], 2)
84
+ expects(:refute_includes).with([], 2, nil)
76
85
  [].should.not.include 2
77
86
  end
78
87
 
88
+ def test_message
89
+ expects(:assert_equal).with(4, 3, 'lol')
90
+ 3.should.blaming('lol') == 4
91
+ end
92
+
93
+ def test_message_2
94
+ object = Object.new
95
+
96
+ expects(:assert).with('grape', 'lol')
97
+ object.expects(:boo?).returns('grape')
98
+
99
+ object.should.blaming('lol').boo
100
+ end
101
+
79
102
  def test_assert_block
80
103
  expects :assert_block
81
104
  should.satisfy { false }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: renvy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rico Sta. Cruz