Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b3933d5a87
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (48 sloc) 2.244 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
require File.dirname(__FILE__) + "/spec_helper"

describe "have_one_to_many_matcher" do

  before :all do
    define_model(:Item){
      one_to_many :comments
    }
    define_model(:Comment)
  end

  subject{ Item }

  describe "messages" do
    describe "without option" do
      it "should contain a description" do
        @matcher = have_one_to_many :comments
        @matcher.description.should == "have a one_to_many association :comments"
      end
      it "should set failure messages" do
        @matcher = have_one_to_many :comments
        @matcher.matches? subject
        @matcher.failure_message.should == "expected Item to have a one_to_many association :comments"
        @matcher.negative_failure_message.should == @matcher.failure_message.gsub("to have", "to not have")
      end
    end
    describe "with options" do
      it "should contain a description" do
        @matcher = have_one_to_many :comments, :class_name => "Comment"
        @matcher.description.should == 'have a one_to_many association :comments with :class_name => "Comment"'
      end
      it "should set failure messages" do
        @matcher = have_one_to_many :comments, :class_name => "Comment"
        @matcher.matches? subject
        @matcher.failure_message.should == 'expected Item to have a one_to_many association :comments with :class_name => "Comment"'
        @matcher.negative_failure_message.should == @matcher.failure_message.gsub("to have", "to not have")
      end
      it "should explicit used options if different than expected" do
        @matcher = have_one_to_many :comments, :class_name => "Price"
        @matcher.matches? subject
        @matcher.failure_message.should == 'expected Item to have a one_to_many association :comments with :class_name => "Price" expected :class_name == "Price" but found "Comment" instead'
        @matcher.negative_failure_message.should == @matcher.failure_message.gsub("to have", "to not have")
      end
    end
  end

  describe "matchers" do
    it{ should have_one_to_many(:comments) }
    it{ should have_one_to_many(:comments, :class_name => "Comment") }
    it{ should_not have_one_to_many(:prices) }
    it{ should_not have_one_to_many(:comments, :class_name => "Price") }
  end

end
Something went wrong with that request. Please try again.