Permalink
Browse files

Clean up style.

  • Loading branch information...
1 parent ff0d364 commit 3d6b8a8ae79644042af0e4fde992ea19a1713091 Gabe Berke-Williams committed Mar 23, 2012
Showing with 30 additions and 37 deletions.
  1. +30 −37 spec/shoulda/active_model/allow_value_matcher_spec.rb
@@ -1,90 +1,83 @@
require 'spec_helper'
describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
-
context "an attribute with a format validation" do
- before do
+ let(:model) do
define_model :example, :attr => :string do
validates_format_of :attr, :with => /abc/
- end
- @model = Example.new
+ end.new
end
- it "should allow a good value" do
- @model.should allow_value("abcde").for(:attr)
+ it "allows a good value" do
+ model.should allow_value("abcde").for(:attr)
end
- it "should not allow a bad value" do
- @model.should_not allow_value("xyz").for(:attr)
+ it "rejects a bad value" do
+ model.should_not allow_value("xyz").for(:attr)
end
- it "should allow several good values" do
- @model.should allow_value("abcde", "deabc").for(:attr)
+ it "allows several good values" do
+ model.should allow_value("abcde", "deabc").for(:attr)
end
- it "should not allow several bad values" do
- @model.should_not allow_value("xyz", "zyx", nil, []).for(:attr)
+ it "rejects several bad values" do
+ model.should_not allow_value("xyz", "zyx", nil, []).for(:attr)
end
end
context "an attribute with a format validation and a custom message" do
- before do
+ let(:model) do
define_model :example, :attr => :string do
validates_format_of :attr, :with => /abc/, :message => 'bad value'
- end
- @model = Example.new
+ end.new
end
- it "should allow a good value" do
- @model.should allow_value('abcde').for(:attr).with_message(/bad/)
+ it "allows a good value" do
+ model.should allow_value('abcde').for(:attr).with_message(/bad/)
end
- it "should not allow a bad value" do
- @model.should_not allow_value('xyz').for(:attr).with_message(/bad/)
+ it "rejects a bad value" do
+ model.should_not allow_value('xyz').for(:attr).with_message(/bad/)
end
end
context "an attribute with several validations" do
- before do
+ let(:model) do
define_model :example, :attr => :string do
validates_presence_of :attr
validates_length_of :attr, :within => 1..5
validates_numericality_of :attr, :greater_than_or_equal_to => 1,
:less_than_or_equal_to => 50000
- end
- @model = Example.new
+ end.new
end
+ bad_values = [nil, "", "abc", "0", "50001", "123456", []]
- it "should allow a good value" do
- @model.should allow_value("12345").for(:attr)
+ it "allows a good value" do
+ model.should allow_value("12345").for(:attr)
end
- bad_values = [nil, "", "abc", "0", "50001", "123456", []]
-
- bad_values.each do |value|
- it "should not allow a bad value (#{value.inspect})" do
- @model.should_not allow_value(value).for(:attr)
+ bad_values.each do |bad_value|
+ it "rejects a bad value (#{bad_value.inspect})" do
+ model.should_not allow_value(bad_value).for(:attr)
end
end
- it "should not allow bad values (#{bad_values.map {|v| v.inspect}.join(', ')})" do
- @model.should_not allow_value(*bad_values).for(:attr)
+ it "rejects bad values (#{bad_values.map(&:inspect).join(', ')})" do
+ model.should_not allow_value(*bad_values).for(:attr)
end
end
context "an AllowValueMatcher with multiple values" do
- before { @matcher = allow_value("foo", "bar").for(:baz) }
-
it "should describe itself" do
- @matcher.description.should eq('allow baz to be set to any of ["foo", "bar"]')
+ matcher = allow_value("foo", "bar").for(:baz) }
+ matcher.description.should == 'allow baz to be set to any of ["foo", "bar"]'
end
end
context "an AllowValueMatcher with a single value" do
- before { @matcher = allow_value("foo").for(:baz) }
-
it "should describe itself" do
- @matcher.description.should eq('allow baz to be set to "foo"')
+ matcher = allow_value("foo").for(:baz)
+ matcher.description.should eq('allow baz to be set to "foo"')
end
end

0 comments on commit 3d6b8a8

Please sign in to comment.