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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e76f0541e0551b3e211d1d0ff2e0e849cc04c3b
4
- data.tar.gz: b573d640fdc5bec51d42d109d75f11a3e1af5f66
3
+ metadata.gz: dba66f9d520a9199781eaa87e225d0513ad6dc2e
4
+ data.tar.gz: 3b530a0219dd914f6e4e4c0bd689a299e60ec74f
5
5
  SHA512:
6
- metadata.gz: b539bf7b07af9967f1d0229397efc54f8187ed6f6ae6ebc5f583655c0ff9af0a57fab3467c26025aedac23be42ad43e830528e6df40d35b19234c314a3cdaa0c
7
- data.tar.gz: c51b4a98b404a13b55ef59da1844faac6356a64561bc277f02e798bf068c762dfabdda7f27900c3f938b7855719546fbb88d1e5e4ab8fc3ae5f347c2ba23f63d
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(clazz)
23
+ process_instance_subject
24
24
  end
25
25
 
26
- def process_instance(clazz)
27
- __memoized.fetch_or_store(:instance) do
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
- process_instance(described)
42
+ call_initializer_with_args(described)
43
43
  else
44
44
  described.new
45
45
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Arguments
5
- VERSION = '0.4.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  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.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-04-12 00:00:00.000000000 Z
11
+ date: 2018-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-support