Hello all,

I trust you are having a good one.

I'm just trying out macros and my first one is taken from the RSpec book
which replaces .....

@obj.should_not be_valid
@obj.should have(1).error_on(:attr)

with the macro....

should_require_attribute Model, :attribute

My first attempt is basic but already I have problems.

The following is called as

it_should_require_attribute Model, :attribute

but I would rather call if as

it_should_require_attribute @model, :attribute.

I prefer this call as I want to use what has been setup in my before(:each)
block -- setting @model and all other housekeeping stuff required for the
tests -- and I can then remove dut_instance = dut.new from the macro.

Alas, my before(:each) block is not being called!! I thought it would be
called when the it in the macro is met.

module ModelMacros
  ## dut - Domain Under Test
  ## aut - Attribute Under Test

  def it_should_require_attribute(dut, aut)
    it "is not valid with missing #{aut}" do
      dut_instance = dut.new
      dut_instance.send("#{aut}=", nil)
      dut_instance.should_not be_valid
      dut_instance.should have(1).error_on(aut.to_sym)
    end
  end
end

Could anyone give me some tips on how to approach macros better for
seamless integration into my tests.

Thank you

-ants
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to