rspec-arguments 0.4.0 → 0.5.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 +15 -0
- data/lib/rspec/arguments/arguments.rb +10 -9
- data/lib/rspec/arguments/example_group.rb +18 -0
- data/lib/rspec/arguments/monkey_patcher.rb +1 -1
- data/lib/rspec/arguments/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dba66f9d520a9199781eaa87e225d0513ad6dc2e
|
4
|
+
data.tar.gz: 3b530a0219dd914f6e4e4c0bd689a299e60ec74f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2563f9e93f5f7bf5902ff1fc81f621a7aa3e8b7eb9633c89a63b0bb0933887c7697838309ab6615c4cda0dbedd4cd8def96e4bec9275a34fe6e368a4b5f5489f
|
7
|
+
data.tar.gz: 033e70876b553919f5f6dc514e6cb16f68e8d1b26be1518d527c118dd93f7d68058ecaad18efbce4c791988159c7e31fde0934737ea98968b4963dc2ec054b99
|
data/README.md
CHANGED
@@ -32,6 +32,21 @@ RSpec.describe Thing do
|
|
32
32
|
end
|
33
33
|
```
|
34
34
|
|
35
|
+
## Install
|
36
|
+
Add the following to your `Gemfile`:
|
37
|
+
```ruby
|
38
|
+
group :test do
|
39
|
+
# ...
|
40
|
+
gem 'rspec-arguments'
|
41
|
+
# ...
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Execute the following command:
|
46
|
+
```bash
|
47
|
+
bundle install
|
48
|
+
```
|
49
|
+
|
35
50
|
## Documentation
|
36
51
|
|
37
52
|
Out-of-the box, RSpec provides us with an implicit `subject` method that instantiates the described class under test, giving us an instance which we can assert on:
|
@@ -20,17 +20,11 @@ module RSpec
|
|
20
20
|
|
21
21
|
return call_method_with_args(clazz, class_method.to_sym) if class_method
|
22
22
|
|
23
|
-
process_instance_subject
|
23
|
+
process_instance_subject
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
28
|
-
call_initializer_with_args(clazz)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def process_instance_subject(clazz)
|
33
|
-
instance = process_instance(clazz)
|
26
|
+
def process_instance_subject
|
27
|
+
instance = self.instance
|
34
28
|
|
35
29
|
method = method_under_test(:method)
|
36
30
|
|
@@ -93,11 +87,18 @@ module RSpec
|
|
93
87
|
|
94
88
|
def search_method_name(metadata, key)
|
95
89
|
description = metadata[:description]
|
90
|
+
|
91
|
+
return description if potential_method?(description)
|
96
92
|
return description unless metadata[:parent_example_group] && metadata[:parent_example_group][key]
|
97
93
|
|
98
94
|
search_method_name(metadata[:parent_example_group], key) if metadata[:parent_example_group]
|
99
95
|
end
|
100
96
|
|
97
|
+
def potential_method?(str)
|
98
|
+
c = str[0]
|
99
|
+
c == '#' || c == '.'
|
100
|
+
end
|
101
|
+
|
101
102
|
def call_initializer_with_args(receiver)
|
102
103
|
call_with_args(
|
103
104
|
self.class.instance_methods,
|
@@ -56,6 +56,24 @@ module RSpec
|
|
56
56
|
_arg_block(METHOD_BLOCK_ARG, name, &block)
|
57
57
|
end
|
58
58
|
|
59
|
+
def instance(name = nil, &block)
|
60
|
+
if name
|
61
|
+
let(name, &block)
|
62
|
+
alias_method :instance, name
|
63
|
+
|
64
|
+
self::NamedSubjectPreventSuper.__send__(:define_method, name) do
|
65
|
+
raise NotImplementedError, "`super` in named instances is not supported"
|
66
|
+
end
|
67
|
+
else
|
68
|
+
let(:instance, &block)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def instance!(name = nil, &block)
|
73
|
+
instance(name, &block)
|
74
|
+
before { instance }
|
75
|
+
end
|
76
|
+
|
59
77
|
private
|
60
78
|
|
61
79
|
def _arg(positional_arg, keyword_arg, name, position = nil, &block)
|
@@ -39,7 +39,7 @@ module RSpec
|
|
39
39
|
if metadata[:rspec_arguments] || metadata[:method] || metadata[:class_method]
|
40
40
|
raise 'Instance is only available when testing class instances or instance methods' if metadata[:class_method]
|
41
41
|
|
42
|
-
|
42
|
+
call_initializer_with_args(described)
|
43
43
|
else
|
44
44
|
described.new
|
45
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-arguments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-support
|