[rspec-devel] Meta specifications or spec. helpers available?

Evgeny evgeny.zislis at gmail.com
Fri Feb 16 15:56:36 EST 2007


Or perhaps there is a simple way to add my own specifications, like:

  specify "should be invalid without login" do
    @user.should_be_invalid_without :login
  end


On 2/16/07, Evgeny <evgeny.zislis at gmail.com> wrote:
>
> Greetings All,
>
> Is there some way that I could do this :
>
> module UserSpecHelper
>   def required_valid_user_attributes
>     { :login => 'monika',
>       :email => 'monika at levinski.com',
>       :password => 'kinky',
>       :password_confirmation => ' kinky',
>       :gender => 'f',
>       :name => 'Monika Levinski'
>     }
>   end
> end
>
> context "A user (in general)" do
>   include UserSpecHelper
>
>   setup do
>     @user = User.new
>   end
>
>   required_valid_user_attributes.keys.each do |attribute|
>     self.class_eval <<-EOT
>     specify "should be invalid without #{attribute}" do
>       @user.attributes =
> required_valid_user_attributes.except(#{attribute})
>       @user.should_not_be_valid
>       @user.errors.on(#{attribute}).should == 'is require'
>       @user.#{attribute} = required_valid_user_attributes[attribute.to_sym
> ]
>       @user.should_be_valid
>     end
>     EOT
>   end
> end
>
>
>
> Because typing the same 7 lines 6 or more times does not look very DRY to
> me ...
>
> Or is there some way to write "specify" helpers or something?
>
>
>
> Regards,
>
> Evgeny
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20070216/b6173978/attachment.html 


More information about the rspec-devel mailing list