Module: RSpec::Core::MemoizedHelpers::ClassMethods
- Defined in:
- lib/rspecz/lets.rb,
lib/rspecz/with.rb,
lib/rspecz/behave.rb,
lib/rspecz/contexts.rb,
lib/rspecz/subjects.rb,
lib/rspecz/aliases/make.rb
Defined Under Namespace
Classes: WithContext
Instance Method Summary collapse
- #create_params(*array) ⇒ Object
- #fwith(name = nil, *values, &block) ⇒ Object
- #fwith_invalid(name = nil, *values, &block) ⇒ Object (also: #fwith_invalids)
- #fwith_missing(name = nil, *values, &block) ⇒ Object (also: #fwith_missings)
- #fwith_nil(*names) ⇒ Object (also: #fwith_nils)
- #fwith_valid(name = nil, *values, &block) ⇒ Object (also: #fwith_valids)
- #multi_behave(*examples) ⇒ Object
- #set(name, value, description = nil, &block) ⇒ Object (also: #value_context)
- #set_block(name, description = nil, &block) ⇒ Object (also: #block_context)
- #set_context(name, &block) ⇒ Object (also: #with_context)
- #set_invalid(name, value = 'invalid-value', description = nil, &block) ⇒ Object (also: #invalid_context)
- #set_invalids(name, *values, &block) ⇒ Object (also: #invalid_contexts)
- #set_missing(name, value = 'missing-value', description = nil, &block) ⇒ Object (also: #nonexist_context)
-
#set_nil(name, description = nil, &block) ⇒ Object
(also: #nil_context)
TODO: あとで綺麗にリファクタリングする TODO: contexts のときに配列が空だったらエラーが出るようにする.
- #set_nils(*names, &block) ⇒ Object (also: #nil_contexts)
- #set_valid(name, value, description = nil, &block) ⇒ Object
- #set_values(name, *values, &block) ⇒ Object (also: #value_contexts)
- #string(*names) ⇒ Object
- #subject_freezed(&block) ⇒ Object
- #with(name = nil, *values, &block) ⇒ Object
- #with_invalid(name = nil, *values, &block) ⇒ Object (also: #with_invalids)
- #with_missing(name = nil, *values, &block) ⇒ Object (also: #with_missings)
- #with_nil(*names) ⇒ Object (also: #with_nils)
- #with_valid(name = nil, *values, &block) ⇒ Object (also: #with_valids)
Instance Method Details
#create_params(*array) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rspecz/lets.rb', line 11 def create_params(*array) __each_if_method_not_defined(array) do |val| let(val) { "test-#{val}" } end let(:with_nil) { false } unless __lib_method_defined?(:with_nil) let(:params) { array.each_with_object({}) do |elem, acc| acc[elem] = send(elem) if send(:with_nil) || !send(elem).nil? end } end |
#fwith(name = nil, *values, &block) ⇒ Object
135 |
# File 'lib/rspecz/with.rb', line 135 def fwith(name = nil, *values, &block) _with(name, nil, true, values, block); end |
#fwith_invalid(name = nil, *values, &block) ⇒ Object Also known as: fwith_invalids
146 |
# File 'lib/rspecz/with.rb', line 146 def fwith_invalid(name = nil, *values, &block) _with(name, 'invalid', true, values, block); end |
#fwith_missing(name = nil, *values, &block) ⇒ Object Also known as: fwith_missings
152 |
# File 'lib/rspecz/with.rb', line 152 def fwith_missing(name = nil, *values, &block) _with(name, 'missing',true, values, block); end |
#fwith_nil(*names) ⇒ Object Also known as: fwith_nils
158 |
# File 'lib/rspecz/with.rb', line 158 def fwith_nil(*names) _with_nil(names, true); end |
#fwith_valid(name = nil, *values, &block) ⇒ Object Also known as: fwith_valids
140 |
# File 'lib/rspecz/with.rb', line 140 def fwith_valid(name = nil, *values, &block) _with(name, 'valid', true, values, block); end |
#multi_behave(*examples) ⇒ Object
5 6 7 8 9 |
# File 'lib/rspecz/behave.rb', line 5 def multi_behave(*examples) examples.each do |example| it_behaves_like example end end |
#set(name, value, description = nil, &block) ⇒ Object Also known as: value_context
23 24 25 26 27 28 |
# File 'lib/rspecz/contexts.rb', line 23 def set(name, value, description = nil, &block) context description || "when #{name} is #{value}" do let(name) { value } instance_exec(name, value, &block) end end |
#set_block(name, description = nil, &block) ⇒ Object Also known as: block_context
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rspecz/contexts.rb', line 60 def set_block(name, description = nil, &block) continue_object = { name: name, descrioption: description, block: block, myobject: self } def continue_object.spec(&block) continue_object = self self[:myobject].context self[:description] || "when #{self[:name]} is different" do let(continue_object[:name]) { instance_eval(&continue_object[:block]) } instance_exec(name, &block) end end continue_object end |
#set_context(name, &block) ⇒ Object Also known as: with_context
81 82 83 84 85 86 |
# File 'lib/rspecz/contexts.rb', line 81 def set_context(name, &block) context "when include context(#{name})" do include_context name instance_eval(&block) end end |
#set_invalid(name, value = 'invalid-value', description = nil, &block) ⇒ Object Also known as: invalid_context
45 46 47 48 49 50 |
# File 'lib/rspecz/contexts.rb', line 45 def set_invalid(name, value = 'invalid-value', description = nil, &block) context description || "when #{name} is not valid(#{value})" do let(name) { value } instance_exec(name, value, &block) end end |
#set_invalids(name, *values, &block) ⇒ Object Also known as: invalid_contexts
53 54 55 56 57 |
# File 'lib/rspecz/contexts.rb', line 53 def set_invalids(name, *values, &block) values.each do |value| invalid_context(name, value, &block) end end |
#set_missing(name, value = 'missing-value', description = nil, &block) ⇒ Object Also known as: nonexist_context
73 74 75 76 77 78 |
# File 'lib/rspecz/contexts.rb', line 73 def set_missing(name, value = 'missing-value', description = nil, &block) context description || "when #{name} does not exist(#{value})" do let(name) { value } instance_exec(name, &block) end end |
#set_nil(name, description = nil, &block) ⇒ Object Also known as: nil_context
TODO: あとで綺麗にリファクタリングする TODO: contexts のときに配列が空だったらエラーが出るようにする
8 9 10 11 12 13 |
# File 'lib/rspecz/contexts.rb', line 8 def set_nil(name, description = nil, &block) context description || "when #{name} is nil" do let(name) { nil } instance_exec(name, &block) end end |
#set_nils(*names, &block) ⇒ Object Also known as: nil_contexts
16 17 18 19 20 |
# File 'lib/rspecz/contexts.rb', line 16 def set_nils(*names, &block) names.each do |name| nil_context(name, &block) end end |
#set_valid(name, value, description = nil, &block) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/rspecz/contexts.rb', line 38 def set_valid(name, value, description = nil, &block) context description || "when #{name} is valid(#{value})" do let(name) { value } instance_exec(name, value, &block) end end |
#set_values(name, *values, &block) ⇒ Object Also known as: value_contexts
31 32 33 34 35 |
# File 'lib/rspecz/contexts.rb', line 31 def set_values(name, *values, &block) values.each do |value| value_context(name, value, &block) end end |
#string(*names) ⇒ Object
5 6 7 8 9 |
# File 'lib/rspecz/lets.rb', line 5 def string(*names) __each_if_method_not_defined(names) do |name| let(name) { "test-#{name}" } end end |
#subject_freezed(&block) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/rspecz/subjects.rb', line 5 def subject_freezed(&block) if RSpec::Core::MemoizedHelpers.module_for(self).method_defined?('now') before(:each) { instance_eval { travel_to(now) } } after(:each) { instance_eval { travel_back } } subject(&block) else subject { raise RuntimeError.new('subject_freezed need you to define let(:now). Please define let(:now)') } end end |
#with(name = nil, *values, &block) ⇒ Object
134 |
# File 'lib/rspecz/with.rb', line 134 def with(name = nil, *values, &block) _with(name, nil, false, values, block); end |
#with_invalid(name = nil, *values, &block) ⇒ Object Also known as: with_invalids
143 |
# File 'lib/rspecz/with.rb', line 143 def with_invalid(name = nil, *values, &block) _with(name, 'invalid', false, values, block); end |
#with_missing(name = nil, *values, &block) ⇒ Object Also known as: with_missings
149 |
# File 'lib/rspecz/with.rb', line 149 def with_missing(name = nil, *values, &block) _with(name, 'missing',false, values, block); end |
#with_nil(*names) ⇒ Object Also known as: with_nils
155 |
# File 'lib/rspecz/with.rb', line 155 def with_nil(*names) _with_nil(names, false); end |
#with_valid(name = nil, *values, &block) ⇒ Object Also known as: with_valids
137 |
# File 'lib/rspecz/with.rb', line 137 def with_valid(name = nil, *values, &block) _with(name, 'valid', false, values, block); end |