tiramisu 0.0.0 → 0.0.1

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.
@@ -0,0 +1,66 @@
1
+ describe :raise do
2
+
3
+ it 'should pass if any exception raised' do
4
+ this = self
5
+ spec rand do
6
+ test(:test) {assert {x}.raise}
7
+ this.assert_equal :__tiramisu_passed__, run(:test)
8
+ end
9
+ end
10
+
11
+ it 'should fail if nothing raised' do
12
+ this = self
13
+ spec rand do
14
+ test(:test) {assert {}.raise}
15
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
16
+ end
17
+ end
18
+
19
+ it 'should pass if type matching' do
20
+ this = self
21
+ spec rand do
22
+ test(:test) {assert {x}.raise(NameError)}
23
+ this.assert_equal :__tiramisu_passed__, run(:test)
24
+ end
25
+ end
26
+
27
+ it 'should fail if wrong exception raised' do
28
+ this = self
29
+ spec rand do
30
+ test(:test) {assert {}.raise(ArgumentError)}
31
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
32
+ end
33
+ end
34
+
35
+ it 'should pass if both type and message matches' do
36
+ this = self
37
+ spec rand do
38
+ test(:test) {assert {x}.raise NameError, /undefined local variable or method/}
39
+ this.assert_equal :__tiramisu_passed__, run(:test)
40
+ end
41
+ end
42
+
43
+ it 'should fail if message does not match' do
44
+ this = self
45
+ spec rand do
46
+ test(:test) {assert {x}.raise(NameError, /blah/)}
47
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
48
+ end
49
+ end
50
+
51
+ it 'should pass if given block validates the raised error' do
52
+ this = self
53
+ spec rand do
54
+ test(:test) {assert {x}.raise {|e| e.class == NameError && e.message =~ /undefined local variable or method/}}
55
+ this.assert_equal :__tiramisu_passed__, run(:test)
56
+ end
57
+ end
58
+
59
+ it 'should fail if given block invalidates raised error' do
60
+ this = self
61
+ spec rand do
62
+ test(:test) {assert {x}.raise {false}}
63
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,91 @@
1
+ describe :receive_and_raise do
2
+
3
+ it 'should pass when received message raises as expected' do
4
+ this = self
5
+ spec rand do
6
+ test :test do
7
+ x = mock(:x)
8
+ expect(x).to_receive(:y).and_raise(NoMethodError)
9
+ x.y
10
+ end
11
+ this.assert_equal :__tiramisu_passed__, run(:test)
12
+ end
13
+ end
14
+
15
+ it 'should pass when received message raises whatever error' do
16
+ this = self
17
+ spec rand do
18
+ test :test do
19
+ x = mock(:x)
20
+ expect(x).to_receive(:y).and_raise
21
+ x.y
22
+ end
23
+ this.assert_equal :__tiramisu_passed__, run(:test)
24
+ end
25
+ end
26
+
27
+ it 'should fail when received message does not raise' do
28
+ this = self
29
+ spec rand do
30
+ test :test do
31
+ x = mock(:x)
32
+ expect(x).to_receive(:to_s).and_raise
33
+ x.to_s
34
+ end
35
+ this.assert_match /Expected a exception to be raised/, run(:test).reason*' '
36
+ end
37
+ end
38
+
39
+ it 'should fail when received message raises a unexpected error type' do
40
+ this = self
41
+ spec rand do
42
+ test :test do
43
+ x = mock(:x)
44
+ expect(x).to_receive(:y).and_raise(NameError)
45
+ x.y
46
+ end
47
+ this.assert_match /Expected a NameError to be raised/, run(:test).reason*' '
48
+ end
49
+ end
50
+
51
+ it 'should fail when error raised by received message is of expected type but error message does not match' do
52
+ this = self
53
+ spec rand do
54
+ test :test do
55
+ x = mock(:x)
56
+ expect(x).to_receive(:y).and_raise(NoMethodError, /blah/)
57
+ x.y
58
+ end
59
+ this.assert_match /to match "blah"/, run(:test).reason*' '
60
+ end
61
+ end
62
+
63
+ it 'should pass if received message raises a error that match by type and message' do
64
+ this = self
65
+ spec rand do
66
+ test :test do
67
+ x = mock(:x)
68
+ expect(x).to_receive(:y).and_raise(NoMethodError, /undefined method `y' for :x:Symbol/)
69
+ x.y
70
+ end
71
+ this.assert_equal :__tiramisu_passed__, run(:test)
72
+ end
73
+ end
74
+
75
+ it 'should pass if error raised by received message are validated by block' do
76
+ this, t, m = self, nil, nil
77
+ spec rand do
78
+ test :test do
79
+ x = mock(:x)
80
+ expect(x).to_receive(:y).and_raise {|e|
81
+ t, m = e.class, e.message
82
+ this.assert_match /undefined method .y. for :x:Symbol/, e.message
83
+ }
84
+ x.y
85
+ end
86
+ run(:test)
87
+ this.assert_equal NoMethodError, t
88
+ this.assert_match /undefined method .y. for :x:Symbol/, m
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,74 @@
1
+ describe :receive_and_return do
2
+
3
+ it 'should pass when expected message returns expected value' do
4
+ this = self
5
+ spec rand do
6
+ test :test do
7
+ x = mock(1)
8
+ expect(x).to_receive(:+).with(1).and_return(2)
9
+ x + 1
10
+ end
11
+ this.assert_equal :__tiramisu_passed__, run(:test)
12
+ end
13
+ end
14
+
15
+ it 'should fail when expected message returns wrong value' do
16
+ this = self
17
+ spec rand do
18
+ test :test do
19
+ x = mock(:x)
20
+ expect(x).to_receive(:to_s).and_return(:y)
21
+ x.to_s
22
+ end
23
+ this.assert_match /Looks like :to_s message never returned expected value/, run(:test).reason*' '
24
+ end
25
+ end
26
+
27
+ it 'should pass when block validates returned value' do
28
+ this = self
29
+ spec rand do
30
+ test :test do
31
+ x = mock(1)
32
+ expect(x).to_receive(:+).with(1).and_return {|v| v == 2}
33
+ x + 1
34
+ end
35
+ this.assert_equal :__tiramisu_passed__, run(:test)
36
+ end
37
+ end
38
+
39
+ it 'should fail when block does not validate returned value' do
40
+ this = self
41
+ spec rand do
42
+ test :test do
43
+ x = mock(1)
44
+ expect(x).to_receive(:+).with(1).and_return {false}
45
+ x + 1
46
+ end
47
+ this.assert_match /Looks like :\+ message never returned expected value/, run(:test).reason*' '
48
+ end
49
+ end
50
+
51
+ it 'should pass when block validates all returned value' do
52
+ this = self
53
+ spec rand do
54
+ test :test do
55
+ x = mock(1)
56
+ expect(x).to_receive(:+).with(1).and_return {|v| v == 2}
57
+ x + 1
58
+ end
59
+ this.assert_equal :__tiramisu_passed__, run(:test)
60
+ end
61
+ end
62
+
63
+ it 'should fail when block does not validate returned value' do
64
+ this = self
65
+ spec rand do
66
+ test :test do
67
+ x = mock(1)
68
+ expect(x).to_receive(:+).with(1).and_return {false}
69
+ x + 1
70
+ end
71
+ this.assert_match /Looks like :\+ message never returned expected value/, run(:test).reason*' '
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,74 @@
1
+ describe :receive_and_throw do
2
+
3
+ it 'should pass when received message throws whatever' do
4
+ this = self
5
+ spec rand do
6
+ test :test do
7
+ x = mock(Class.new {define_singleton_method(:y) {throw :z}})
8
+ expect(x).to_receive(:y).and_throw
9
+ x.y
10
+ end
11
+ this.assert_equal :__tiramisu_passed__, run(:test)
12
+ end
13
+ end
14
+
15
+ it 'should pass when received message throws expected symbol' do
16
+ this = self
17
+ spec rand do
18
+ test :test do
19
+ x = mock(Class.new {define_singleton_method(:y) {throw :z}})
20
+ expect(x).to_receive(:y).and_throw(:z)
21
+ x.y
22
+ end
23
+ this.assert_equal :__tiramisu_passed__, run(:test)
24
+ end
25
+ end
26
+
27
+ it 'should fail when received message throws nothing' do
28
+ this = self
29
+ spec rand do
30
+ test :test do
31
+ x = mock(Class.new {define_singleton_method(:y) {}})
32
+ expect(x).to_receive(:y).and_throw
33
+ x.y
34
+ end
35
+ this.assert_match /Expected a symbol to be thrown/, run(:test).reason*' '
36
+ end
37
+ end
38
+
39
+ it 'should fail when received message throws wrong symbol' do
40
+ this = self
41
+ spec rand do
42
+ test :test do
43
+ x = mock(Class.new {define_singleton_method(:y) {throw :z}})
44
+ expect(x).to_receive(:y).and_throw(:a)
45
+ x.y
46
+ end
47
+ this.assert_match /Expected :a to be thrown/, run(:test).reason*' '
48
+ end
49
+ end
50
+
51
+ it 'should pass when given block validates thrown symbol' do
52
+ this = self
53
+ spec rand do
54
+ test :test do
55
+ x = mock(Class.new {define_singleton_method(:y) {throw :z}})
56
+ expect(x).to_receive(:y).and_throw {|s| s == :z}
57
+ x.y
58
+ end
59
+ this.assert_equal :__tiramisu_passed__, run(:test)
60
+ end
61
+ end
62
+
63
+ it 'should fail when block does not validate thrown symbol' do
64
+ this = self
65
+ spec rand do
66
+ test :test do
67
+ x = mock(Class.new {define_singleton_method(:y) {throw :z}})
68
+ expect(x).to_receive(:y).and_throw {false}
69
+ x.y
70
+ end
71
+ this.assert_match /Looks like wrong or no symbol thrown/, run(:test).reason*' '
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,48 @@
1
+ describe :receive do
2
+
3
+ it 'should pass when a message expected and received' do
4
+ this = self
5
+ spec rand do
6
+ test :test do
7
+ x = mock(:x)
8
+ expect(x).to_receive(:class)
9
+ x.class
10
+ end
11
+ this.assert_equal :__tiramisu_passed__, run(:test)
12
+ end
13
+ end
14
+
15
+ it 'should fail when a expected message not received' do
16
+ this = self
17
+ spec rand do
18
+ test :test do
19
+ x = mock(:x)
20
+ expect(x).to_receive(:class)
21
+ end
22
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
23
+ end
24
+ end
25
+
26
+ it 'should pass when no message expected and no message received' do
27
+ this = self
28
+ spec rand do
29
+ test :test do
30
+ x = mock(:x)
31
+ fail_if(x).receive(:class)
32
+ end
33
+ this.assert_equal :__tiramisu_passed__, run(:test)
34
+ end
35
+ end
36
+
37
+ it 'should fail when unexpected message received' do
38
+ this = self
39
+ spec rand do
40
+ test :test do
41
+ x = mock(:x)
42
+ fail_if(x).receive(:class)
43
+ x.class
44
+ end
45
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,62 @@
1
+ describe :receive_with do
2
+
3
+ it 'should pass when called with correct arguments' do
4
+ this = self
5
+ spec rand do
6
+ test :test do
7
+ x = mock(1)
8
+ expect(x).to_receive(:+).with(1)
9
+ x + 1
10
+ end
11
+ this.assert_equal :__tiramisu_passed__, run(:test)
12
+ end
13
+ end
14
+
15
+ it 'should fail when called without arguments' do
16
+ this = self
17
+ spec rand do
18
+ test :test do
19
+ x = mock([])
20
+ expect(x).to_receive(:join).with('')
21
+ x.join
22
+ end
23
+ this.assert_match /Looks like :join message never was called with expected arguments/, run(:test).reason*' '
24
+ end
25
+ end
26
+
27
+ it 'should fail when called with wrong arguments' do
28
+ this = self
29
+ spec rand do
30
+ test :test do
31
+ x = mock([])
32
+ expect(x).to_receive(:join).with('')
33
+ x.join('/')
34
+ end
35
+ this.assert_match /Looks like :join message never was called with expected arguments/, run(:test).reason*' '
36
+ end
37
+ end
38
+
39
+ it 'should pass when block validates arguments' do
40
+ this = self
41
+ spec rand do
42
+ test :test do
43
+ x = mock(1)
44
+ expect(x).to_receive(:+).with {|a| a == [1]}
45
+ x + 1
46
+ end
47
+ this.assert_equal :__tiramisu_passed__, run(:test)
48
+ end
49
+ end
50
+
51
+ it 'should fail when block does not validate arguments' do
52
+ this = self
53
+ spec rand do
54
+ test :test do
55
+ x = mock(1)
56
+ expect(x).to_receive(:+).with {false}
57
+ x + 1
58
+ end
59
+ this.assert_match /Looks like :\+ message never was called with expected arguments/, run(:test).reason*' '
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,90 @@
1
+ describe :refute_raise do
2
+
3
+ it 'should pass if no exception expected and no exception raised' do
4
+ this = self
5
+ spec rand do
6
+ test(:test) {refute {}.raise}
7
+ this.assert_equal :__tiramisu_passed__, run(:test)
8
+ end
9
+ end
10
+
11
+ it 'should fail if exception raised when not expected' do
12
+ this = self
13
+ spec rand do
14
+ test(:test) {refute {x}.raise}
15
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
16
+ end
17
+ end
18
+
19
+ it 'should fail if exception of specific type negated but nothing raised' do
20
+ this = self
21
+ spec rand do
22
+ test(:test) {refute {}.raise NameError}
23
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
24
+ end
25
+ end
26
+
27
+ it 'should fail if exception with specific message negated but nothing raised' do
28
+ this = self
29
+ spec rand do
30
+ test(:test) {refute {}.raise nil, /blah/}
31
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
32
+ end
33
+ end
34
+
35
+ it 'should pass if it raises a exception type different from negated one' do
36
+ this = self
37
+ spec rand do
38
+ test(:test) {refute {x}.raise(ArgumentError)}
39
+ this.assert_equal :__tiramisu_passed__, run(:test)
40
+ end
41
+ end
42
+
43
+ it 'should fail if it raises a exception of same type as negated one' do
44
+ this = self
45
+ spec rand do
46
+ test(:test) {refute {x}.raise NameError}
47
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
48
+ end
49
+ end
50
+
51
+ it 'should pass if it raises a exception with a message different from negated one' do
52
+ this = self
53
+ spec rand do
54
+ test(:test) {refute {x}.raise nil, /blah/}
55
+ this.assert_equal :__tiramisu_passed__, run(:test)
56
+ end
57
+ end
58
+
59
+ it 'should fail if it raises a exception with a message matching negated one' do
60
+ this = self
61
+ spec rand do
62
+ test(:test) {refute {x}.raise nil, /undefined local variable/}
63
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
64
+ end
65
+ end
66
+
67
+ it 'should pass if raised type is not of negated type and error message does not match negated message' do
68
+ this = self
69
+ spec rand do
70
+ test(:test) {refute {x}.raise ArgumentError, /blah/}
71
+ this.assert_equal :__tiramisu_passed__, run(:test)
72
+ end
73
+ end
74
+
75
+ it 'should fail if raised type is of negated type' do
76
+ this = self
77
+ spec rand do
78
+ test(:test) {refute {x}.raise NameError, /blah/}
79
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
80
+ end
81
+ end
82
+
83
+ it 'should fail if error message matches negated one' do
84
+ this = self
85
+ spec rand do
86
+ test(:test) {refute {x}.raise ArgumentError, /undefined local variable/}
87
+ this.assert_equal Tiramisu::GenericFailure, run(:test).class
88
+ end
89
+ end
90
+ end