renvy 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ v0.2.1 - May 17, 2011
2
+ ---------------------
3
+
4
+ Massive API overhaul to match Test::Spec API.
5
+
6
+ v0.1.3 - May 17, 2011
7
+ ---------------------
8
+
9
+ ### Fixed:
10
+ * Fixed operations (`a.should < b` and so on)
11
+
12
+ v0.1.2 - May 17, 2011
13
+ ---------------------
14
+
15
+ ### Added:
16
+ * Added `in_delta?` and `in_eplison?` for floats.
17
+
18
+ ### Changed:
19
+ * Doing `include?`, `instance_of?`, `equal?` and so on will use the
20
+ appropriate MiniTest matchers instead of generic asserts.
21
+
22
+ v0.1.1 - May 17, 2011
23
+ ---------------------
24
+
25
+ Initial version.
data/README.md CHANGED
@@ -13,27 +13,53 @@ Then you may use it as so:
13
13
 
14
14
  ```ruby
15
15
  obj.should == 2 # => assert_equal 2, obj
16
- obj.should ~= /regex/ # => assert_match /regex/, obj
16
+ obj.should =~ /regex/ # => assert_match /regex/, obj
17
17
  obj.should != 3 # => assert_not_equal 3, obj
18
- obj.should.be.true! # => assert obj
19
- obj.should.be.false!
18
+ obj.should.nil # => assert_nil obj
19
+ obj.should.respond_to(:freeze) # => assert_respond_to obj, :freeze
20
20
 
21
- # Anything else will just pass thru (.be is optional):
22
- obj.should.nil? # => assert obj.nil?
23
- obj.should.be.nil? # => assert obj.nil?
24
- obj.should.respond_to?(:freeze) # => assert obj.respond_to?(:freeze)
21
+ # Note that .be, .a and .an are optional.
22
+ obj.should.nil # => assert_nil obj
23
+ obj.should.be.nil # => assert_nil obj
24
+ obj.should.be.a.nil # => assert_nil obj
25
25
 
26
26
  # You can also use should_not:
27
27
  obj.should_not == 3
28
28
  obj.should_not.be.nil?
29
29
 
30
+ # Anything else will pass through with a ?:
31
+ obj.should.be.good_looking # => assert obj.good_looking?
32
+
30
33
  should.raise(Error) { lol }
31
34
  should_not.raise { puts "hi" }
32
35
  ```
33
36
 
34
- ### Extending
37
+ ## Wrapped assertions
38
+
39
+ These are based from Test::Spec.
40
+
41
+ | assert_equal | should.equal, should == |
42
+ | assert_not_equal | should.not.equal, should.not == |
43
+ | assert_same | should.be |
44
+ | assert_not_same | should.not.be |
45
+ | assert_nil | should.be.nil |
46
+ | assert_not_nil | should.not.be.nil |
47
+ | assert_in_delta | should.be.close |
48
+ | assert_match | should.match, should =~ |
49
+ | assert_no_match | should.not.match, should.not =~ |
50
+ | assert_instance_of | should.be.an.instance_of |
51
+ | assert_kind_of | should.be.a.kind_of |
52
+ | assert_respond_to | should.respond_to |
53
+ | assert_raise | should.raise |
54
+ | assert_nothing_raised | should.not.raise |
55
+ | assert_throws | should.throw |
56
+ | assert_nothing_thrown | should.not.throw |
57
+ | assert_block | should.satisfy |
58
+
59
+ ## Extending
35
60
 
36
- Create your new matcher in a module, then use `REnvy::Should.add`.
61
+ Need to create your own matchers? Create your new matcher in a module, then
62
+ use `REnvy::Should.add`.
37
63
 
38
64
  ```ruby
39
65
  module DanceMatcher
@@ -52,5 +78,16 @@ REnvy::Should.add DanceMatcher
52
78
  dancer.should.boogie_all_night!
53
79
  ```
54
80
 
55
- (You may also use `REnvy::Should::Be.add` to restrict it to the `.should.be`
56
- context.)
81
+ ## REnvy vs. Test::Spec
82
+
83
+ [Test-Spec](http://test-spec.rubyforge.org/test-spec/) accomplishes roughly
84
+ the same thing as REnvy, but:
85
+
86
+ * REnvy does it with lean <4kb code.
87
+
88
+ * REnvy can play alongside with other Test::Unit wrappers. In fact, is made
89
+ to be used with gems like Contest, Shoulda, and other similar tools.
90
+
91
+ * REnvy does not provide contexts or 'should'-like syntax like Test::Spec
92
+ does. For that, I suggest using REnvy alongside
93
+ [Contest](http://github.com/citrusbyte/contest).
@@ -23,7 +23,7 @@ require 'test/unit'
23
23
  # should_not.raise { puts "hi" }
24
24
  #
25
25
  module REnvy
26
- VERSION = "0.1.1"
26
+ VERSION = "0.2.1"
27
27
 
28
28
  def self.version
29
29
  VERSION
@@ -32,10 +32,11 @@ module REnvy
32
32
  class Should
33
33
  attr_reader :left
34
34
 
35
- def self.init(test)
35
+ def self.init(test) # :nodoc:
36
36
  @@test = test
37
37
  end
38
38
 
39
+ # Includes a module to extend .should with more matchers.
39
40
  def self.add(extension)
40
41
  self.send :include, extension
41
42
  end
@@ -45,46 +46,53 @@ module REnvy
45
46
  @neg = neg
46
47
  end
47
48
 
48
- def negative?
49
- @neg
49
+ def be() self; end
50
+ def a() self; end
51
+ def an() self; end
52
+
53
+ def negative?() @neg; end
54
+ def positive?() !@neg; end
55
+ def test() @@test; end
56
+ def not() @neg = true; self; end
57
+
58
+ def ==(right) assert_or_refute :equal, right, left; end
59
+ def !=(right) assert_or_refute_not :equal, right, left; end
60
+ def =~(right) assert_or_refute :match, right, left; end
61
+ def >(right) assert_or_refute :operator, left, :>, right; end
62
+ def <(right) assert_or_refute :operator, left, :<, right; end
63
+ def >=(right) assert_or_refute :operator, left, :>=, right; end
64
+ def <=(right) assert_or_refute :operator, left, :<=, right; end
65
+ def include(right) assert_or_refute :includes, left, right; end
66
+ def instance_of(right) assert_or_refute :instance_of, right, left; end
67
+ def kind_of(right) assert_or_refute :kind_of, right, left; end
68
+ def nil() assert_or_refute :nil, left; end
69
+ def same(right) assert_or_refute :same, right, left; end
70
+ def respond_to(right) assert_or_refute :respond_to, left, right; end
71
+ def empty() assert_or_refute :empty, left; end
72
+ def satisfy(&blk) assert_or_refute :block, &blk; end
73
+
74
+ def match(right) self =~ right; end
75
+ def equal(right) self == right; end
76
+
77
+ def close(right, d=0.001) assert_or_refute :in_delta, right, left, d; end
78
+ def in_epsilon(right, d=0.001) assert_or_refute :in_epsilon, right, left, d; end
79
+
80
+ def assert_or_refute(what, *args, &blk)
81
+ test.send (positive? ? :"assert_#{what}" : :"refute_#{what}"), *args, &blk
50
82
  end
51
83
 
52
- def positive?
53
- !@neg
84
+ def assert_or_refute_not(what, *args)
85
+ test.send (negative? ? :"assert_#{what}" : :"refute_#{what}"), *args
54
86
  end
55
87
 
56
- def test
57
- @@test
58
- end
59
-
60
- def ==(right)
61
- if positive?
62
- test.send :assert_equal, right, left
63
- else
64
- test.send :assert_not_equal, right, left
65
- end
66
- end
67
-
68
- def !=(right)
88
+ def throw(what=nil, &blk)
69
89
  if positive?
70
- test.send :assert_not_equal, right, left
90
+ test.send :assert_throws, what, &blk
71
91
  else
72
- test.send :assert_equal, right, left
92
+ test.send :assert_nothing_thrown, &blk
73
93
  end
74
94
  end
75
95
 
76
- def =~(right)
77
- if positive?
78
- test.send :assert_match, right, left
79
- else
80
- test.send :assert, ! (left =~ right)
81
- end
82
- end
83
-
84
- def be
85
- Be.new(left, @neg)
86
- end
87
-
88
96
  def raise(ex=StandardError, &blk)
89
97
  if positive?
90
98
  test.send :assert_raises, ex, &blk
@@ -94,29 +102,11 @@ module REnvy
94
102
  end
95
103
 
96
104
  def method_missing(meth, *args, &blk)
97
- result = left.send(meth, *args, &blk)
98
- if positive?
99
- @test.send :assert, result
100
- else
101
- @test.send :assert, ! result
102
- end
103
- end
104
- end
105
-
106
- class Should::Be < Should
107
- def true!
108
- if positive?
109
- test.send :assert, left
110
- else
111
- test.send :assert, ! left
112
- end
113
- end
114
-
115
- def false!
105
+ result = left.send(:"#{meth}?", *args, &blk)
116
106
  if positive?
117
- test.send :assert, ! left
107
+ test.send :assert, result
118
108
  else
119
- test.send :assert, left
109
+ test.send :assert, ! result
120
110
  end
121
111
  end
122
112
  end
@@ -25,7 +25,7 @@ class ExtensionTest < Test::Unit::TestCase
25
25
  a = %w(a b c)
26
26
  b = %w(b c A)
27
27
 
28
- a.shouldnt.be.like b
28
+ a.should_not.be.like b
29
29
  end
30
30
 
31
31
  def test_extension_3
@@ -1,30 +1,83 @@
1
1
  require File.expand_path('../../lib/renvy', __FILE__)
2
+ require 'mocha'
3
+
4
+ class Foo
5
+ def get_true?
6
+ true
7
+ end
8
+
9
+ def get_false?
10
+ false
11
+ end
12
+ end
2
13
 
3
14
  class REnvyTest < Test::Unit::TestCase
4
15
  def test_should
5
- 2.should == 2
6
- 2.shouldnt == 3
16
+ 2.should == 2
17
+ 2.should_not == 3
18
+ 2.should.not == 3
7
19
 
8
- 2.should != 3
9
- 2.shouldnt != 2
20
+ 2.should != 3
21
+ 2.should_not != 2
22
+ 2.should.not != 2
10
23
 
11
24
  "hi".should =~ /hi/
12
- "hi".shouldnt =~ /HI/
13
-
14
- true.should.be.true!
15
- "ye".should.be.true!
16
- true.shouldnt.be.false!
17
-
18
- false.should.be.false!
19
- false.shouldnt.be.true!
25
+ "hi".should.match /hi/
26
+ "hi".should_not =~ /HI/
27
+ "hi".should.not.match /HI/
20
28
 
21
29
  @foo.should.be.nil?
22
- 1000.shouldnt.be.nil?
30
+ 1000.should_not.be.nil?
23
31
 
24
- "".should.respond_to?(:empty?)
25
- "".shouldnt.respond_to?(:lolwhat)
32
+ "".should.respond_to(:empty?)
33
+ "".should_not.respond_to(:lolwhat)
26
34
 
27
- shouldnt.raise { 2 + 2 }
35
+ should_not.raise { 2 + 2 }
28
36
  should.raise(ZeroDivisionError) { 2 / 0 }
37
+
38
+ [].should.be.empty
39
+ [].should.empty
40
+
41
+ [1].should_not.be.empty
42
+ [1].should.include(1)
43
+
44
+ 2.should < 3
45
+ 1.should < 2
46
+ 2.should <= 2
47
+ 2.should <= 4
48
+ 4.should >= 4
49
+ 4.should >= 3
50
+
51
+ Object.new.should.respond_to(:freeze)
52
+ Object.new.should.be.kind_of(Object)
53
+ Object.new.should.be.an.instance_of(Object)
54
+
55
+ a = Object.new
56
+ b = a
57
+ a.should.be.equal?(b)
58
+ a.should_not.be.equal?(Object.new)
59
+
60
+ Math::PI.should.be.close(22.0/7, 0.1)
61
+
62
+ should.throw(:x) { throw :x }
63
+ should.not.throw { 2 + 2 }
64
+
65
+ Foo.new.should.not.get_false
66
+ Foo.new.should.get_true
67
+ end
68
+
69
+ def test_include
70
+ expects(:assert_includes).with([], 2)
71
+ [].should.include 2
72
+ end
73
+
74
+ def test_include_not
75
+ expects(:refute_includes).with([], 2)
76
+ [].should.not.include 2
77
+ end
78
+
79
+ def test_assert_block
80
+ expects :assert_block
81
+ should.satisfy { false }
29
82
  end
30
83
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: renvy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rico Sta. Cruz
@@ -37,6 +37,7 @@ files:
37
37
  - lib/renvy.rb
38
38
  - test/extension_test.rb
39
39
  - test/renvy_test.rb
40
+ - HISTORY.md
40
41
  - README.md
41
42
  - Rakefile
42
43
  has_rdoc: true