| Module | ActiveMatchers::Matchers |
| In: |
lib/matchers/association_matcher.rb
lib/matchers/response_matchers.rb lib/matchers/validation_matcher.rb lib/matchers.rb |
Use to confirm whether a response is/is not a 404
response.should be_a_404
# File lib/matchers.rb, line 98
98: def be_a_404
99: ResponseMatchers::NotFoundMatcher.new
100: end
Test belongs_to :parent
Model.should belong_to(:parent)
Test belongs_to :parent, :class_name => "CustomClass", :foreign_key => "some_id"
Model.should belong_to(:parent).with_options(
:class_name => "CustomClass", :foreign_key => "some_id")
# File lib/matchers.rb, line 39
39: def belong_to(*fields)
40: AssociationMatcher.new(:belongs_to, *fields)
41: end
Test has_and_belongs_to_many :items
Model.should have_and_belong_to_many(:items)
Test has_and_belongs_to_many :items, :class_name => "CustomClass"
Model.should have_one(:item).with_options(
:class_name => "CustomClass")
# File lib/matchers.rb, line 72
72: def have_and_belong_to_many(*fields)
73: AssociationMatcher.new(:has_and_belongs_to_many, *fields)
74: end
Test has_many :items
Model.should have_many(:items)
Test has_many :items, :class_name => "CustomClass", :foreign_key => "some_id"
Model.should have_many(:items).with_options(
:class_name => "CustomClass", :foreign_key => "some_id")
# File lib/matchers.rb, line 50
50: def have_many(*fields)
51: AssociationMatcher.new(:has_many, *fields)
52: end
Test has_one :item
Model.should have_one(:item)
Test has_one :item, :class_name => "CustomClass", :foreign_key => "some_id"
Model.should have_one(:item).with_options(
:class_name => "CustomClass", :foreign_key => "some_id")
# File lib/matchers.rb, line 61
61: def have_one(*fields)
62: AssociationMatcher.new(:has_one, *fields)
63: end
Test validates_length_of :name matches database field length
Model.should limit_length_of(:name).using(@valid_attributes)
Test validates_length_of :name, :maximum => 255
Model.should limit_length_of(:name).to(255).using(@valid_attributes)
# File lib/matchers.rb, line 28
28: def limit_length_of(*fields)
29: ValidationMatcher.new(:length, *fields).using(@base_attributes)
30: end
Test validates_presence_of :name
Model.should need(:name).using(@valid_attributes)
Test validates_uniqueness_of :name
Model.should need(:name).to_be_unique.using(@valid_attributes)
Test presence of at least one field being required
Model.should need.one_of(:first_name, :last_name).using(@valid_attributes)
# File lib/matchers.rb, line 16
16: def need(*fields)
17: ValidationMatcher.new(:require, *fields).using(@base_attributes)
18: end
Use to confirm whether a response redirected
response.should redirect
response.should_not redirect
response.should redirect.to("url")
response.should_not redirect.to("url")
# File lib/matchers.rb, line 109
109: def redirect
110: ResponseMatchers::RedirectMatcher.new
111: end
# File lib/matchers.rb, line 90
90: def succeed
91: ResponseMatchers::SuccessMatcher.new(@controller)
92: end
Useful for multiple requests using the same base attributes
using(@valid_attributes) do
Model.should need(:name)
Model.should limit_length_of(:name).to(100)
end
# File lib/matchers.rb, line 83
83: def using(base_attributes={}, &block)
84: @base_attributes = base_attributes
85: yield
86: @base_attributes= {}
87: end