开发者

Rails 3: how to test models that use an acts_as-style plugin?

I've written a very simple plugin (following the Rails guide) that adds a has_sex method to ActiveRecord::Base, which, when called, adds a few instance methods (for getting appropriate pronouns and so on) to the model and validates :sex, inclusion: {in: %w(male female)}.

How should I write unit tests on models that utilise this?

I could test that Person < HasSex::InstanceMethods, which will be true if has_sex was called on Person (and the plugin tests ensure that the desired behaviour results). But I wonder if this is really testing imp开发者_StackOverflow中文版lementation and not behaviour?

On the other hand, I could test if Person.sex only allows values 'male' and 'female', and that the various instance methods have the desired effect, but then I'm duplicating tests that I wrote for the plugin itself.

What's the best approach here? For the record, I'm testing with Test::Unit and Shoulda, but I'm more interested in the principle rather than the finer details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜