named_let 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/named_let.rb +54 -19
- data/lib/named_let/version.rb +1 -1
- metadata +45 -67
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c9fc8085b3f8e7b8a9259ec6b721d8902c8ab8a
|
4
|
+
data.tar.gz: 2147cb0b463b4e516379e16d3a9f2d160ac48c09
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd513aa2a072274af34021a9b23682b4238f8647a54e6c420bf61cdfc322db55786c79a50f6fc4466c5facd40939981187036e7ee336cc05ca488d3c79119099
|
7
|
+
data.tar.gz: eccf40df57a6ec87fc5064cc5845a2f1c1a73822d9c493a37a0d7ed0a5841e5e07609c5446ab41a0dd16b67b373f3efcc5df9a96048569d7c2ccea33c7a32eee
|
data/lib/named_let.rb
CHANGED
@@ -38,33 +38,68 @@ module NamedLet
|
|
38
38
|
klass = RSpec::Core::MemoizedHelpers::ClassMethods
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
def extend_for_reporting(obj, the_name)
|
42
|
+
return obj if obj.nil?
|
43
|
+
|
44
|
+
# if given -d/--debug option, append calling original ones.(ruby-debug required)
|
45
|
+
call_super = begin ;$DEBUG or Debugger.started? rescue LoadError; nil; end
|
46
|
+
|
47
|
+
inject_code = lambda{|o, code| begin; o.instance_eval code; rescue TypeError; end }
|
48
|
+
escape = lambda{|str| str.gsub(/\"/, '\\"')}
|
49
|
+
|
50
|
+
genereate_wrapper_code = lambda{|o, method|
|
51
|
+
original_result = escape.call(o.send(method)) if call_super
|
52
|
+
"def #{method}; \"#{the_name}\" #{call_super ? " + \" (#{original_result})\"" : ''} ;end"
|
53
|
+
}
|
54
|
+
|
55
|
+
to_s_code = genereate_wrapper_code.call(obj, :to_s)
|
56
|
+
inspect_code = genereate_wrapper_code.call(obj, :inspect)
|
57
|
+
|
58
|
+
inject_code.call(obj, to_s_code)
|
59
|
+
inject_code.call(obj, inspect_code)
|
60
|
+
obj
|
61
|
+
end
|
62
|
+
module_function :extend_for_reporting
|
46
63
|
|
47
|
-
|
64
|
+
klass.class_eval do
|
65
|
+
if RSpec::Core::Version::STRING < "3.0"
|
48
66
|
|
49
|
-
|
50
|
-
|
67
|
+
# for Rspec2
|
68
|
+
def named_let(name, label = nil, &block)
|
51
69
|
|
52
|
-
|
53
|
-
escape = lambda{|str| str.gsub(/\"/, '\\"')}
|
70
|
+
the_name = label || name
|
54
71
|
|
55
|
-
|
56
|
-
|
57
|
-
|
72
|
+
define_method(name) do
|
73
|
+
__memoized.fetch(name) {|k|
|
74
|
+
__memoized[k] = instance_eval(&block).tap{|o| NamedLet.extend_for_reporting(o, the_name) }
|
58
75
|
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
else
|
79
|
+
# for Rspec3
|
80
|
+
def named_let(name, label = nil, &block)
|
81
|
+
# We have to pass the block directly to `define_method` to
|
82
|
+
# allow it to use method constructs like `super` and `return`.
|
83
|
+
raise "#let or #subject called without a block" if block.nil?
|
84
|
+
RSpec::Core::MemoizedHelpers.module_for(self).__send__(:define_method, name, &block)
|
59
85
|
|
60
|
-
|
61
|
-
inspect_code = genereate_wrapper_code.call(o, :inspect)
|
86
|
+
the_name = label || name
|
62
87
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
88
|
+
# Apply the memoization. The method has been defined in an ancestor
|
89
|
+
# module so we can use `super` here to get the value.
|
90
|
+
if block.arity == 1
|
91
|
+
define_method(name) {
|
92
|
+
__memoized.fetch_or_store(name) {
|
93
|
+
super(RSpec.current_example, &nil).tap{|o| NamedLet.extend_for_reporting(o, the_name) }
|
94
|
+
}
|
95
|
+
}
|
96
|
+
else
|
97
|
+
define_method(name) {
|
98
|
+
__memoized.fetch_or_store(name) { super(&nil).tap{|o| NamedLet.extend_for_reporting(o, the_name) }}
|
99
|
+
}
|
100
|
+
end
|
67
101
|
end
|
102
|
+
|
68
103
|
end
|
69
104
|
|
70
105
|
def named_let!(name, label = nil, &block)
|
data/lib/named_let/version.rb
CHANGED
metadata
CHANGED
@@ -1,62 +1,52 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: named_let
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 5
|
10
|
-
version: 0.1.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Tomohito Ozaki
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2015-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: rspec
|
23
|
-
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
27
17
|
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
33
20
|
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec-core
|
37
21
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
41
31
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
47
34
|
type: :runtime
|
48
|
-
|
49
|
-
|
50
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: "'named_let(:name){ obj }' changes the value which returns 'obj#to_s'
|
42
|
+
and 'obj#inspect' to :name, then output of 'rspec -format d' be improved more readable."
|
43
|
+
email:
|
51
44
|
- ozaki@yuroyoro.com
|
52
45
|
executables: []
|
53
|
-
|
54
46
|
extensions: []
|
55
|
-
|
56
47
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
|
59
|
-
- .gitignore
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
60
50
|
- Gemfile
|
61
51
|
- LICENSE
|
62
52
|
- README.md
|
@@ -64,39 +54,27 @@ files:
|
|
64
54
|
- lib/named_let.rb
|
65
55
|
- lib/named_let/version.rb
|
66
56
|
- named_let.gemspec
|
67
|
-
has_rdoc: true
|
68
57
|
homepage: https://github.com/yuroyoro/named_let
|
69
58
|
licenses: []
|
70
|
-
|
59
|
+
metadata: {}
|
71
60
|
post_install_message:
|
72
61
|
rdoc_options: []
|
73
|
-
|
74
|
-
require_paths:
|
62
|
+
require_paths:
|
75
63
|
- lib
|
76
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
-
|
78
|
-
requirements:
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
79
66
|
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
version: "0"
|
85
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
|
-
requirements:
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
88
71
|
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
|
91
|
-
segments:
|
92
|
-
- 0
|
93
|
-
version: "0"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
94
74
|
requirements: []
|
95
|
-
|
96
75
|
rubyforge_project: named_let
|
97
|
-
rubygems_version:
|
76
|
+
rubygems_version: 2.2.0
|
98
77
|
signing_key:
|
99
|
-
specification_version:
|
78
|
+
specification_version: 4
|
100
79
|
summary: named_let can be used to make the rspec's output easier to read.
|
101
80
|
test_files: []
|
102
|
-
|