Skip to content
This repository
Browse code

Clean up style.

  • Loading branch information...
commit 3d6b8a8ae79644042af0e4fde992ea19a1713091 1 parent ff0d364
Gabe Berke-Williams authored March 23, 2012
67  spec/shoulda/active_model/allow_value_matcher_spec.rb
... ...
@@ -1,90 +1,83 @@
1 1
 require 'spec_helper'
2 2
 
3 3
 describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
4  
-
5 4
   context "an attribute with a format validation" do
6  
-    before do
  5
+    let(:model) do
7 6
       define_model :example, :attr => :string do
8 7
         validates_format_of :attr, :with => /abc/
9  
-      end
10  
-      @model = Example.new
  8
+      end.new
11 9
     end
12 10
 
13  
-    it "should allow a good value" do
14  
-      @model.should allow_value("abcde").for(:attr)
  11
+    it "allows a good value" do
  12
+      model.should allow_value("abcde").for(:attr)
15 13
     end
16 14
 
17  
-    it "should not allow a bad value" do
18  
-      @model.should_not allow_value("xyz").for(:attr)
  15
+    it "rejects a bad value" do
  16
+      model.should_not allow_value("xyz").for(:attr)
19 17
     end
20 18
 
21  
-    it "should allow several good values" do
22  
-      @model.should allow_value("abcde", "deabc").for(:attr)
  19
+    it "allows several good values" do
  20
+      model.should allow_value("abcde", "deabc").for(:attr)
23 21
     end
24 22
 
25  
-    it "should not allow several bad values" do
26  
-      @model.should_not allow_value("xyz", "zyx", nil, []).for(:attr)
  23
+    it "rejects several bad values" do
  24
+      model.should_not allow_value("xyz", "zyx", nil, []).for(:attr)
27 25
     end
28 26
   end
29 27
 
30 28
   context "an attribute with a format validation and a custom message" do
31  
-    before do
  29
+    let(:model) do
32 30
       define_model :example, :attr => :string do
33 31
         validates_format_of :attr, :with => /abc/, :message => 'bad value'
34  
-      end
35  
-      @model = Example.new
  32
+      end.new
36 33
     end
37 34
 
38  
-    it "should allow a good value" do
39  
-      @model.should allow_value('abcde').for(:attr).with_message(/bad/)
  35
+    it "allows a good value" do
  36
+      model.should allow_value('abcde').for(:attr).with_message(/bad/)
40 37
     end
41 38
 
42  
-    it "should not allow a bad value" do
43  
-      @model.should_not allow_value('xyz').for(:attr).with_message(/bad/)
  39
+    it "rejects a bad value" do
  40
+      model.should_not allow_value('xyz').for(:attr).with_message(/bad/)
44 41
     end
45 42
   end
46 43
 
47 44
   context "an attribute with several validations" do
48  
-    before do
  45
+    let(:model) do
49 46
       define_model :example, :attr => :string do
50 47
         validates_presence_of     :attr
51 48
         validates_length_of       :attr, :within => 1..5
52 49
         validates_numericality_of :attr, :greater_than_or_equal_to => 1,
53 50
           :less_than_or_equal_to    => 50000
54  
-      end
55  
-      @model = Example.new
  51
+      end.new
56 52
     end
  53
+    bad_values = [nil, "", "abc", "0", "50001", "123456", []]
57 54
 
58  
-    it "should allow a good value" do
59  
-      @model.should allow_value("12345").for(:attr)
  55
+    it "allows a good value" do
  56
+      model.should allow_value("12345").for(:attr)
60 57
     end
61 58
 
62  
-    bad_values = [nil, "", "abc", "0", "50001", "123456", []]
63  
-
64  
-    bad_values.each do |value|
65  
-      it "should not allow a bad value (#{value.inspect})" do
66  
-        @model.should_not allow_value(value).for(:attr)
  59
+    bad_values.each do |bad_value|
  60
+      it "rejects a bad value (#{bad_value.inspect})" do
  61
+        model.should_not allow_value(bad_value).for(:attr)
67 62
       end
68 63
     end
69 64
 
70  
-    it "should not allow bad values (#{bad_values.map {|v| v.inspect}.join(', ')})" do
71  
-      @model.should_not allow_value(*bad_values).for(:attr)
  65
+    it "rejects bad values (#{bad_values.map(&:inspect).join(', ')})" do
  66
+      model.should_not allow_value(*bad_values).for(:attr)
72 67
     end
73 68
   end
74 69
 
75 70
   context "an AllowValueMatcher with multiple values" do
76  
-    before { @matcher = allow_value("foo", "bar").for(:baz) }
77  
-
78 71
     it "should describe itself" do
79  
-      @matcher.description.should eq('allow baz to be set to any of ["foo", "bar"]')
  72
+      matcher = allow_value("foo", "bar").for(:baz) }
  73
+      matcher.description.should == 'allow baz to be set to any of ["foo", "bar"]'
80 74
     end
81 75
   end
82 76
 
83 77
   context "an AllowValueMatcher with a single value" do
84  
-    before { @matcher = allow_value("foo").for(:baz) }
85  
-
86 78
     it "should describe itself" do
87  
-      @matcher.description.should eq('allow baz to be set to "foo"')
  79
+      matcher = allow_value("foo").for(:baz)
  80
+      matcher.description.should eq('allow baz to be set to "foo"')
88 81
     end
89 82
   end
90 83
 

0 notes on commit 3d6b8a8

Please sign in to comment.
Something went wrong with that request. Please try again.