pretentious 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -1
- data/example.rb +7 -0
- data/lib/pretentious/rspec_generator.rb +7 -1
- data/lib/pretentious/version.rb +1 -1
- data/spec/fibonacci_spec.rb +1 -1
- data/spec/test_class1_spec.rb +24 -18
- data/spec/test_class2_spec.rb +2 -2
- data/spec/test_class3_spec.rb +6 -6
- data/spec/test_class4_spec.rb +3 -3
- data/test_classes.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fb899b0d269ad993d7e7d5f9b7fe61cfd6b226c
|
4
|
+
data.tar.gz: 6c3d3400c4eb0ce26f1e7dad7937673b9ee90275
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5033ed7b8019458b6068043963580818e313f56b083194b22092c2f7754a9754bd5d0a1bfd89aa3c10e92025dac58b42855a62e48a62be76bd9270d26d732411
|
7
|
+
data.tar.gz: d1e12ecc2d3b839919bc1e8a0294b9d53a76e94f1ab4c7916e12944a9621bfe5634b993696efcd255189380d09b5f986a5b9c49ed96b3a4f93a4e1efa5b1097e
|
data/README.md
CHANGED
@@ -288,6 +288,25 @@ RSpec.describe TestClass3 do
|
|
288
288
|
|
289
289
|
Note that creating another instance of TestClass3 will result in the creation of another Scenario
|
290
290
|
|
291
|
+
## Capturing Exceptions
|
292
|
+
|
293
|
+
Exceptions thrown by method calls should generate the appropriate exception test case. Just make sure
|
294
|
+
that you rescue inside your example file like below:
|
295
|
+
|
296
|
+
```ruby
|
297
|
+
begin
|
298
|
+
test_class_one.something_is_wrong
|
299
|
+
rescue Exception=>e
|
300
|
+
end
|
301
|
+
```
|
302
|
+
|
303
|
+
should generate the following in rspec
|
304
|
+
|
305
|
+
```ruby
|
306
|
+
# TestClass1#something_is_wrong when passed should return StandardError
|
307
|
+
expect { @fixture.something_is_wrong }.to raise_error
|
308
|
+
```
|
309
|
+
|
291
310
|
## Things to do after
|
292
311
|
|
293
312
|
Since your tests are already written, and hopefully nobody notices its written by a machine, you may just leave it
|
@@ -300,9 +319,12 @@ a bdd'er/tdd'er.
|
|
300
319
|
|
301
320
|
Computers are bad at mind reading (for now) and they don't really know your expectation of "correctness", as such
|
302
321
|
it assumes your code is correct and can only use equality based matchers. It can also only reliably match
|
303
|
-
primitive data types
|
322
|
+
primitive data types, hashes, Procs and arrays to a degree. More complex expectations are unfortunately left for the humans
|
304
323
|
to resolve.
|
305
324
|
|
325
|
+
Procs that return a constant value will be resolved properly. However variable return values are currently still
|
326
|
+
not generated properly will return a stub (future versions may use sourcify to resolve Procs for ruby 1.9)
|
327
|
+
|
306
328
|
Also do note that it tries its best to determine how your fixtures are created, as well as the types
|
307
329
|
of your parameters and does so by figuring out (recursively) the components that your object needs. Failure can happen during this process.
|
308
330
|
|
data/example.rb
CHANGED
@@ -42,6 +42,13 @@ Pretentious.spec_for(TestClass1, TestClass2, TestClass3, TestClass4) do
|
|
42
42
|
class_to_test4.message
|
43
43
|
}
|
44
44
|
|
45
|
+
begin
|
46
|
+
test_class_one.something_is_wrong
|
47
|
+
rescue Exception=>e
|
48
|
+
end
|
49
|
+
|
50
|
+
test_class_one.just_returns_true
|
51
|
+
|
45
52
|
end
|
46
53
|
|
47
54
|
Pretentious.spec_for(Digest::MD5) do
|
@@ -161,7 +161,13 @@ class Pretentious::RspecGenerator
|
|
161
161
|
|
162
162
|
info_blocks_arr.each do |block|
|
163
163
|
|
164
|
-
|
164
|
+
params_desc_str = if block[:params].size > 0
|
165
|
+
"when passed #{desc_params(block)}"
|
166
|
+
else
|
167
|
+
""
|
168
|
+
end
|
169
|
+
|
170
|
+
buffer("# #{context_prefix}#{k} #{params_desc_str} should return #{block[:result]}", 3)
|
165
171
|
generate_expectation(fixture, k, let_variables, declaration, block[:params], block[:block], block[:result])
|
166
172
|
|
167
173
|
whitespace
|
data/lib/pretentious/version.rb
CHANGED
data/spec/fibonacci_spec.rb
CHANGED
data/spec/test_class1_spec.rb
CHANGED
@@ -13,7 +13,7 @@ RSpec.describe TestClass1 do
|
|
13
13
|
it 'should pass current expectations' do
|
14
14
|
|
15
15
|
|
16
|
-
# TestClass1#message
|
16
|
+
# TestClass1#message should return test
|
17
17
|
expect( @fixture.message ).to eq("test")
|
18
18
|
|
19
19
|
end
|
@@ -22,40 +22,46 @@ RSpec.describe TestClass1 do
|
|
22
22
|
context 'Scenario 2' do
|
23
23
|
before do
|
24
24
|
|
25
|
-
|
26
|
-
another_object = TestClass1.new(
|
27
|
-
|
25
|
+
var_2161332560 = "test"
|
26
|
+
another_object = TestClass1.new(var_2161332560)
|
27
|
+
var_2161318440 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
|
28
28
|
|
29
|
-
@fixture = TestClass1.new(
|
29
|
+
@fixture = TestClass1.new(var_2161318440)
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should pass current expectations' do
|
34
34
|
|
35
|
-
|
36
|
-
another_object = TestClass1.new(
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
var_2161332560 = "test"
|
36
|
+
another_object = TestClass1.new(var_2161332560)
|
37
|
+
var_2161318440 = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
|
38
|
+
var_2161201340 = Proc.new { |message|
|
39
|
+
var_2161318440
|
40
40
|
}
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
e = nil
|
43
|
+
var_2161188420 = Proc.new {
|
44
44
|
# Variable return values ... can't figure out what goes in here...
|
45
45
|
}
|
46
46
|
|
47
47
|
|
48
|
-
# TestClass1#print_message
|
48
|
+
# TestClass1#print_message should return
|
49
49
|
expect( @fixture.print_message ).to be_nil
|
50
50
|
|
51
|
-
# TestClass1#print_message
|
51
|
+
# TestClass1#print_message should return
|
52
52
|
expect( @fixture.print_message ).to be_nil
|
53
53
|
|
54
|
-
# TestClass1#set_block
|
55
|
-
expect( @fixture.set_block &
|
54
|
+
# TestClass1#set_block should return #<Pretentious::RecordedProc:0x00000101a23eb8@example.rb:73>
|
55
|
+
expect( @fixture.set_block &var_2161201340 ).to eq(var_2161201340)
|
56
56
|
|
57
|
-
# TestClass1#call_block
|
58
|
-
expect( @fixture.call_block &
|
57
|
+
# TestClass1#call_block should return {:hello=>"world", :test=>#<TestClass1:0x00000101a6a110 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2161332560=>"message"}>, :arr_1=>[1, 2, 3, 4, 5, #<TestClass1:0x00000101a6a110 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2161332560=>"message"}>], :sub_hash=>{:yes=>true, :obj=>#<TestClass1:0x00000101a6a110 @message="test", @_init_arguments={:params=>["test"]}, @_variable_names={2161332560=>"message"}>}}
|
58
|
+
expect( @fixture.call_block &var_2161188420 ).to eq(var_2161318440)
|
59
|
+
|
60
|
+
# TestClass1#something_is_wrong should return StandardError
|
61
|
+
expect { @fixture.something_is_wrong }.to raise_error
|
62
|
+
|
63
|
+
# TestClass1#just_returns_true should return true
|
64
|
+
expect( @fixture.just_returns_true ).to be true
|
59
65
|
|
60
66
|
end
|
61
67
|
end
|
data/spec/test_class2_spec.rb
CHANGED
@@ -13,10 +13,10 @@ RSpec.describe TestClass2 do
|
|
13
13
|
it 'should pass current expectations' do
|
14
14
|
|
15
15
|
|
16
|
-
# TestClass2#print_message
|
16
|
+
# TestClass2#print_message should return
|
17
17
|
expect( @fixture.print_message ).to be_nil
|
18
18
|
|
19
|
-
# TestClass2#print_message
|
19
|
+
# TestClass2#print_message should return
|
20
20
|
expect( @fixture.print_message ).to be_nil
|
21
21
|
|
22
22
|
end
|
data/spec/test_class3_spec.rb
CHANGED
@@ -5,8 +5,8 @@ RSpec.describe TestClass3 do
|
|
5
5
|
context 'Scenario 1' do
|
6
6
|
before do
|
7
7
|
|
8
|
-
|
9
|
-
another_object = TestClass1.new(
|
8
|
+
var_2161332560 = "test"
|
9
|
+
another_object = TestClass1.new(var_2161332560)
|
10
10
|
args = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
|
11
11
|
test_class_one = TestClass1.new(args)
|
12
12
|
args_1 = "This is message 2"
|
@@ -19,7 +19,7 @@ RSpec.describe TestClass3 do
|
|
19
19
|
it 'should pass current expectations' do
|
20
20
|
|
21
21
|
|
22
|
-
# TestClass3#show_messages
|
22
|
+
# TestClass3#show_messages should return awesome!!!
|
23
23
|
expect( @fixture.show_messages ).to eq("awesome!!!")
|
24
24
|
|
25
25
|
end
|
@@ -28,8 +28,8 @@ RSpec.describe TestClass3 do
|
|
28
28
|
context 'Scenario 2' do
|
29
29
|
before do
|
30
30
|
|
31
|
-
|
32
|
-
another_object = TestClass1.new(
|
31
|
+
var_2161332560 = "test"
|
32
|
+
another_object = TestClass1.new(var_2161332560)
|
33
33
|
args = {hello: "world", test: another_object, arr_1: [1, 2, 3, 4, 5, another_object], sub_hash: {yes: true, obj: another_object}}
|
34
34
|
test_class_one = TestClass1.new(args)
|
35
35
|
args_1 = "This is message 2"
|
@@ -42,7 +42,7 @@ RSpec.describe TestClass3 do
|
|
42
42
|
it 'should pass current expectations' do
|
43
43
|
|
44
44
|
|
45
|
-
# TestClass3#show_messages
|
45
|
+
# TestClass3#show_messages should return awesome!!!
|
46
46
|
expect( @fixture.show_messages ).to eq("awesome!!!")
|
47
47
|
|
48
48
|
end
|
data/spec/test_class4_spec.rb
CHANGED
@@ -5,13 +5,13 @@ RSpec.describe TestClass4 do
|
|
5
5
|
context 'Scenario 1' do
|
6
6
|
before do
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
var_2161332560 = "test"
|
9
|
+
var_2161220900 = Proc.new {
|
10
10
|
"test"
|
11
11
|
}
|
12
12
|
|
13
13
|
|
14
|
-
@fixture = TestClass4.new &
|
14
|
+
@fixture = TestClass4.new &var_2161220900
|
15
15
|
|
16
16
|
end
|
17
17
|
|
data/test_classes.rb
CHANGED