spec/examples/attribute_examples.rb in riveter-0.0.4 vs spec/examples/attribute_examples.rb in riveter-0.0.5

- old
+ new

@@ -1,10 +1,14 @@ require 'spec_helper' -shared_examples_for "an attribute" do |type, default_value, another_value, *args, &block| +shared_examples_for "an attribute" do |type, default_value, *args, &block| options = args.extract_options! + # override these in "calling" specs + let(:assigned_value) { default_value } + let(:expected_value) { assigned_value } + describe type do let(:name) { "a_#{type}" } let(:instance) { subject.new() } describe "as attribute" do @@ -16,19 +20,19 @@ it { instance.attributes.should include(name.to_s) } it { instance.should respond_to(name)} it { instance.should respond_to("#{name}=")} it "assigns attribute in initializer" do - a = subject.new(name => another_value) - a.send(name).should eq(another_value) - a.attributes[name].should eq(another_value) + a = subject.new(name => assigned_value) + a.send(name).should eq(expected_value) + a.attributes[name].should eq(expected_value) end it "assigns attribute" do a = subject.new() - a.send("#{name}=", another_value) - a.attributes[name].should eq(another_value) + a.send("#{name}=", assigned_value) + a.attributes[name].should eq(expected_value) end end describe "as required attribute" do before do @@ -42,9 +46,22 @@ before do subject.send :"attr_#{type}", name, *args, options.merge(:default => default_value) end it { instance.send(name).should eq(default_value)} + end + + describe "with supplied converter block" do + let(:mock_block) { Mock::Block.new() } + + before do + subject.send :"attr_#{type}", name, *args, options.merge(:default => default_value), &mock_block + end + + it { + expect(mock_block).to receive(:call).at_least(:once) + instance.send(name) + } end end end shared_examples_for "a class with attributes" do |type|