rspec-arguments 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 383418f2f244c0de2f9c46c4d22e1c325cf8d28c
4
- data.tar.gz: 249db8f96b9175a39407740dcfceefd9db94d7d9
3
+ metadata.gz: 7e76f0541e0551b3e211d1d0ff2e0e849cc04c3b
4
+ data.tar.gz: b573d640fdc5bec51d42d109d75f11a3e1af5f66
5
5
  SHA512:
6
- metadata.gz: 1966c9c0c5d385c23100a13d06e01e9b5d12bfbe64e22dcbc2e057cfbf7b03bc4803e5272f613b3e7e5d4b5bf5e470b6204b47a191b80edf380b5573aca71b71
7
- data.tar.gz: 8b703ff0cca9d0c53ee5859468afa1f372d1dc3198ae57689d18bfa1526512cb2cd97687c26d30e9cfa39bd15d057b21654fa9c9ac11fc35b1c0112982dbc83d
6
+ metadata.gz: b539bf7b07af9967f1d0229397efc54f8187ed6f6ae6ebc5f583655c0ff9af0a57fab3467c26025aedac23be42ad43e830528e6df40d35b19234c314a3cdaa0c
7
+ data.tar.gz: c51b4a98b404a13b55ef59da1844faac6356a64561bc277f02e798bf068c762dfabdda7f27900c3f938b7855719546fbb88d1e5e4ab8fc3ae5f347c2ba23f63d
@@ -15,17 +15,22 @@ 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, &block)
18
+ def process_subject(clazz)
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, &block)
23
+ process_instance_subject(clazz)
24
+ end
25
+
26
+ def process_instance(clazz)
27
+ __memoized.fetch_or_store(:instance) do
28
+ call_initializer_with_args(clazz)
29
+ end
24
30
  end
25
31
 
26
32
  def process_instance_subject(clazz)
27
- instance = call_initializer_with_args(clazz)
28
- yield(instance)
33
+ instance = process_instance(clazz)
29
34
 
30
35
  method = method_under_test(:method)
31
36
 
@@ -17,7 +17,7 @@ module RSpec
17
17
 
18
18
  if described.is_a?(Class)
19
19
  if metadata[:rspec_arguments] || metadata[:method] || metadata[:class_method]
20
- process_subject(described) { |instance| __memoized.fetch_or_store(:instance) { instance } }
20
+ process_subject(described)
21
21
  else
22
22
  described.new
23
23
  end
@@ -31,8 +31,20 @@ module RSpec
31
31
  # Reference to the instantiated object, if testing an instance or instance method (but not class method).
32
32
  #
33
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' }
34
+ __memoized.fetch_or_store(:instance) do
35
+ metadata = self.class.metadata
36
+ described = described_class || metadata.fetch(:description_args).first
37
+
38
+ if described.is_a?(Class)
39
+ if metadata[:rspec_arguments] || metadata[:method] || metadata[:class_method]
40
+ raise 'Instance is only available when testing class instances or instance methods' if metadata[:class_method]
41
+
42
+ process_instance(described)
43
+ else
44
+ described.new
45
+ end
46
+ end
47
+ end
36
48
  end
37
49
  end
38
50
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module Arguments
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-arguments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Costa