spec/lib/sinclair/method_definition_spec.rb in sinclair-1.4.1 vs spec/lib/sinclair/method_definition_spec.rb in sinclair-1.4.2

- old
+ new

@@ -21,44 +21,90 @@ "Use #{described_class}.from to initialize a proper object" ) end end - context 'when method was defined with a string' do + context 'when method was defined with a string for instance' do subject(:method_definition) do - described_class.from(method_name, code) + definition_class.new(method_name, code) end + let(:definition_class) { described_class::InstanceStringDefinition } + let(:code) { '@x = @x.to_i + 1' } it_behaves_like 'MethodDefinition#build without cache' context 'with cached options' do subject(:method_definition) do - described_class.from(method_name, code, cached: cached_option) + definition_class.new(method_name, code, cached: cached_option) end it_behaves_like 'MethodDefinition#build with cache options' end end - context 'when method was defined with a block' do + context 'when method was defined with a block for instance' do subject(:method_definition) do - described_class.from(method_name) do + definition_class.new(method_name) do @x = @x.to_i + 1 end end + let(:definition_class) { described_class::InstanceBlockDefinition } + it_behaves_like 'MethodDefinition#build without cache' context 'with cached options' do subject(:method_definition) do - described_class.from(method_name, cached: cached_option) do + definition_class.new(method_name, cached: cached_option) do @x = @x.to_i + 1 end end it_behaves_like 'MethodDefinition#build with cache options' + end + end + + context 'when method was defined with a string for class' do + subject(:method_definition) do + definition_class.new(method_name, code) + end + + let(:definition_class) { described_class::ClassStringDefinition } + + let(:code) { '@x = @x.to_i + 1' } + + it_behaves_like 'ClassMethodDefinition#build without cache' + + context 'with cached options' do + subject(:method_definition) do + definition_class.new(method_name, code, cached: cached_option) + end + + it_behaves_like 'ClassMethodDefinition#build with cache options' + end + end + + context 'when method was defined with a block for class' do + subject(:method_definition) do + definition_class.new(method_name) do + @x = @x.to_i + 1 + end + end + + let(:definition_class) { described_class::ClassBlockDefinition } + + it_behaves_like 'ClassMethodDefinition#build without cache' + + context 'with cached options' do + subject(:method_definition) do + definition_class.new(method_name, cached: cached_option) do + @x = @x.to_i + 1 + end + end + + it_behaves_like 'ClassMethodDefinition#build with cache options' end end end end