rspec-arguments 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/rspec/arguments/arguments.rb +3 -2
- data/lib/rspec/arguments/example_group.rb +4 -0
- data/lib/rspec/arguments/monkey_patcher.rb +20 -2
- data/lib/rspec/arguments/version.rb +1 -1
- 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: 383418f2f244c0de2f9c46c4d22e1c325cf8d28c
|
4
|
+
data.tar.gz: 249db8f96b9175a39407740dcfceefd9db94d7d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1966c9c0c5d385c23100a13d06e01e9b5d12bfbe64e22dcbc2e057cfbf7b03bc4803e5272f613b3e7e5d4b5bf5e470b6204b47a191b80edf380b5573aca71b71
|
7
|
+
data.tar.gz: 8b703ff0cca9d0c53ee5859468afa1f372d1dc3198ae57689d18bfa1526512cb2cd97687c26d30e9cfa39bd15d057b21654fa9c9ac11fc35b1c0112982dbc83d
|
data/README.md
CHANGED
@@ -20,10 +20,14 @@ RSpec.describe Thing do
|
|
20
20
|
|
21
21
|
it { is_expected.to be_a(Thing) }
|
22
22
|
|
23
|
-
describe '#
|
23
|
+
describe '#perform', :method do
|
24
24
|
method_arg(:save) { true }
|
25
25
|
|
26
26
|
it { is_expected.to eq(save) }
|
27
|
+
|
28
|
+
it 'should be able to access the class instance' do
|
29
|
+
expect(instance.perform(save: save)).to eq(subject)
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
29
33
|
```
|
@@ -15,16 +15,17 @@ module RSpec
|
|
15
15
|
METHOD_KEYWORD_ARG = METHOD_ARG_PREFIX + KEYWORD_ARG_SUFFIX
|
16
16
|
METHOD_BLOCK_ARG = METHOD_ARG_PREFIX + BLOCK_ARG_SUFFIX
|
17
17
|
|
18
|
-
def process_subject(clazz)
|
18
|
+
def process_subject(clazz, &block)
|
19
19
|
class_method = method_under_test(:class_method)
|
20
20
|
|
21
21
|
return call_method_with_args(clazz, class_method.to_sym) if class_method
|
22
22
|
|
23
|
-
process_instance_subject(clazz)
|
23
|
+
process_instance_subject(clazz, &block)
|
24
24
|
end
|
25
25
|
|
26
26
|
def process_instance_subject(clazz)
|
27
27
|
instance = call_initializer_with_args(clazz)
|
28
|
+
yield(instance)
|
28
29
|
|
29
30
|
method = method_under_test(:method)
|
30
31
|
|
@@ -59,6 +59,8 @@ module RSpec
|
|
59
59
|
private
|
60
60
|
|
61
61
|
def _arg(positional_arg, keyword_arg, name, position = nil, &block)
|
62
|
+
metadata[:rspec_arguments] = true
|
63
|
+
|
62
64
|
let(name, &block)
|
63
65
|
|
64
66
|
if position.is_a?(Integer)
|
@@ -69,6 +71,8 @@ module RSpec
|
|
69
71
|
end
|
70
72
|
|
71
73
|
def _arg_block(block_arg, name, &block)
|
74
|
+
metadata[:rspec_arguments] = true
|
75
|
+
|
72
76
|
let(name, &block)
|
73
77
|
|
74
78
|
let(block_arg.+(name.to_s).to_sym) { send(name) }
|
@@ -12,10 +12,28 @@ module RSpec
|
|
12
12
|
#
|
13
13
|
def subject
|
14
14
|
__memoized.fetch_or_store(:subject) do
|
15
|
-
|
16
|
-
described
|
15
|
+
metadata = self.class.metadata
|
16
|
+
described = described_class || metadata.fetch(:description_args).first
|
17
|
+
|
18
|
+
if described.is_a?(Class)
|
19
|
+
if metadata[:rspec_arguments] || metadata[:method] || metadata[:class_method]
|
20
|
+
process_subject(described) { |instance| __memoized.fetch_or_store(:instance) { instance } }
|
21
|
+
else
|
22
|
+
described.new
|
23
|
+
end
|
24
|
+
else
|
25
|
+
described
|
26
|
+
end
|
17
27
|
end
|
18
28
|
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Reference to the instantiated object, if testing an instance or instance method (but not class method).
|
32
|
+
#
|
33
|
+
def instance
|
34
|
+
subject # Ensures subject has been loaded
|
35
|
+
__memoized.fetch_or_store(:instance) { raise 'Instance is only available when testing class instances or instance methods' }
|
36
|
+
end
|
19
37
|
end
|
20
38
|
end
|
21
39
|
end
|