Sha256: a41ff00c57b7a204eaf87816917a46164752e56d6798315fe586f905c66bf819
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
require 'spec_helper' require 'method_decorators/decorators/precondition' describe Precondition do let(:receiver) { double(:receiver) } let(:method) { double(:method, :call => :secret, :receiver => receiver) } let(:block) { proc { |arg| true } } subject { Precondition.new(&block) } describe "#call" do it "raises when the precondition fails" do subject.stub(:passes?){ false } expect{ subject.call(method) }.to raise_error(ArgumentError) end it "executes the method when authorization succeeds" do subject.stub(:passes?){ true } subject.call(method).should == :secret end end describe "acceptance" do let(:klass) do Class.new Base do def initialize(x) @x = x end +Precondition.new{ |a| a + @x < 10 } def multiply(a) a * @x end end end subject { klass.new(3) } it "calls the method if the precondition passes" do subject.multiply(2).should == 6 end it "raises if the precondition passes" do expect{ subject.multiply(8) }.to raise_error(ArgumentError) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
method_decorators-0.9.1 | spec/decorators/precondition_spec.rb |