Module Remarkable::ActiveRecord::Describe
In: lib/remarkable_activerecord/describe.rb

Overwrites describe to provide quick way to configure your subject:

  describe Post
    should_validate_presente_of :title

    describe :published => true do
      should_validate_presence_of :published_at
    end
  end

This is the same as:

  describe Post
    should_validate_presente_of :title

    describe "when published is true" do
      subject { Post.new(:published => true) }
      should_validate_presence_of :published_at
    end
  end

The string can be localized using I18n. An example yml file is:

  locale:
    remarkable:
      active_record:
        describe:
          each: "{{key}} is {{value}}"
          prepend: "when "
          connector: " and "

You can also call subject attributes to set the default attributes for a subject. You can even mix with a fixture replacement tool:

  describe Post
    # Fixjour example
    subject_attributes { valid_post_attributes }

    describe :published => true do
      should_validate_presence_of :published_at
    end
  end

You can retrieve the merged result of all attributes given using the subject_attributes instance method:

  describe Post
    # Fixjour example
    subject_attributes { valid_post_attributes }

    describe :published => true do
      it "should have default subject attributes" do
        subject_attributes.should == { :title => 'My title', :published => true }
      end
    end
  end

Methods

Classes and Modules

Module Remarkable::ActiveRecord::Describe::ClassMethods

Public Instance methods

Returns a hash with the subject attributes declared using the subject_attributes class method and the attributes given using the describe method.

  describe Post
    subject_attributes { valid_post_attributes }

    describe :published => true do
      it "should have default subject attributes" do
        subject_attributes.should == { :title => 'My title', :published => true }
      end
    end
  end

[Source]

     # File lib/remarkable_activerecord/describe.rb, line 189
189:       def subject_attributes
190:         default = self.class.default_subject_attributes
191:         default = self.instance_eval(&default) if default.is_a?(Proc)
192:         default ||= {}
193: 
194:         default.merge(self.class.describe_subject_attributes || {})
195:       end

[Validate]