validates_formatting_of 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 252aa1819d51863c3f14259517c47693e15cc0e9
4
- data.tar.gz: 1b77589cba97bc4bd7b5f1620254f005d3199b68
3
+ metadata.gz: b287c47de58a743ad0e3bbcd926418f177d8a612
4
+ data.tar.gz: edab15de4ab01ee66ca38c98a18e22f87a0a4ca3
5
5
  SHA512:
6
- metadata.gz: 78f53eaef519be439ad5cec07dc7b508a093edc0de77f7df0bc87f52b5b0a4d3996c260208900fb597c11e8830ffb319fece4e6f051e4ce15d3a97a9737ced5d
7
- data.tar.gz: 0cfbe50ae8897a4126f7fe37748d7267db315aeb02142c2a569fe725df136f4edcef3c0496074c6707313931a623b2b52fbe2ac18fe7bd3d5d545a088b928ca4
6
+ metadata.gz: ae394a30bb518a12b6f3ac1e3a72ef0cd5638d85cdd0e569b18c7f77e0c533235df5bb6766921be4d30de34b6b1390247548aaf065ef0fb0ea1bc005b6b024c0
7
+ data.tar.gz: 716d98e86d5a2782f180a571ef4a772f015d07cebbed209854edf7f7b8c2f9cbd61b9c7d579861252ff8a9ea2c82687b0e07c08c7d78918c39ef15b3d61b5a45
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-version
19
+ .overcommit.yml
@@ -2,5 +2,6 @@ script: bundle exec rspec spec
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - rbx-19mode
5
+ - 2.1.0
6
+ - 2.2.2
6
7
  - jruby-19mode
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in validates_format_of.gemspec
4
4
  gemspec
@@ -6,12 +6,12 @@
6
6
 
7
7
  The `validates_formatting_of` gem adds several convenient methods to validate things such as emails, urls, and phone numbers in a Rails application.
8
8
 
9
- # Unsupported versions
9
+ # Supported Ruby Versions
10
10
 
11
- Please note that this gem takes advantage of regular expression features which are newer features in Ruby. Because of this, certain versions are not supported:
12
-
13
- * 1.8.7
14
- * Ruby Enterprise Edition (REE)
11
+ * 1.9.3
12
+ * 2.0.0
13
+ * 2.1.0
14
+ * 2.2.0
15
15
 
16
16
  # Installation
17
17
 
@@ -61,7 +61,7 @@ Say, for example, you have identical plain-old regex validations for different c
61
61
  While very unrealistic, these examples should serve their purpose in demonstrating this ability.
62
62
 
63
63
  ```ruby
64
- # config/initializers/validates_foramatting_of.rb
64
+ # config/initializers/validates_formatting_of.rb
65
65
  ValidatesFormattingOf::Method.add :loweralpha, /[a-z]/, "must be lowercase and no spaces"
66
66
  ValidatesFormattingOf::Method.add :upperalpha, /[A-Z]/, "must be uppercase and no spaces"
67
67
  ValidatesFormattingOf::Method.add :weak_password, /[a-zA-Z0-9]{8,}/, "must contain only letters and numbers and be at least 8 characters long".
@@ -71,20 +71,23 @@ Keep in mind, since this gem is only ActiveModel-dependent, you should be able t
71
71
 
72
72
  # Built-in Validations
73
73
 
74
- `validates_formatting_of` has the following build-in validations:
75
-
76
- ### Email
74
+ `validates_formatting_of` has the following built-in validations:
77
75
 
78
76
  ```ruby
79
- # non ActiveRecord::Base example. This is the least you need to get validations running.
80
- class User
81
-
82
- include ActiveModel::Validations
83
- extend ValidatesFormattingOf::ModelAdditions
84
-
85
- attr_accessor :email
77
+ class ExampleModel < ActiveRecord::Base
78
+ validates_formatting_of :email, :using => :email # Email
79
+ validates_formatting_of :first_name, :using => :alpha # Letters
80
+ validates_formatting_of :website, :using => :url # URLs
81
+ validates_formatting_of :text, :using => :alphanum # Alpha-numeric
82
+ validates_formatting_of :zipcode, :using => :us_zip # US Zip Code
83
+ validates_formatting_of :phone, :using => :us_phone # US Phone Numbers
84
+ validates_formatting_of :ip, :using => :ip_address_v4 # IPv4
85
+ validates_formatting_of :ssn, :using => :ssn # Social Security Numbers
86
+ validates_formatting_of :color, :using => :hex_color # Hexadecimal Colors
87
+ validates_formatting_of :amount, :using => :dollars # Dollars
86
88
 
87
- validates_formatting_of :email, :using => :email
89
+ # Credit Card (Visa, Mastercard, Discover, and American Express)
90
+ validates_formatting_of :cc, :using => :credit_card
88
91
  end
89
92
  ```
90
93
 
@@ -96,83 +99,18 @@ class User < ActiveRecord::Base
96
99
  end
97
100
  ```
98
101
 
99
- ### URL
100
-
101
- ```ruby
102
- class Sites < ActiveRecord::Base
103
- validates_formatting_of :website, :using => :url
104
- end
105
- ```
106
-
107
- ### Alpha
108
-
109
- ```ruby
110
- class Name < ActiveRecord::Base
111
- validates_formatting_of :first_name, :using => :alpha
112
- end
113
- ```
114
-
115
- ### Alphanumeric
116
-
117
- ```ruby
118
- class Sites < ActiveRecord::Base
119
- validates_formatting_of :text, :using => :alphanum
120
- end
121
- ```
122
-
123
- ### Credit Card (Visa, Mastercard, Discover, and American Express)
124
-
125
- ```ruby
126
- class Purchases < ActiveRecord::Base
127
- validates_formatting_of :cc, :using => :credit_card
128
- end
129
- ```
102
+ ### Plain Old Ruby Objects
130
103
 
131
- ### US Zipcodes
104
+ If you are not using ActiveRecord or want to use it on some other type of object, this is the least you need to get validations running.
132
105
 
133
106
  ```ruby
134
- class Location < ActiveRecord::Base
135
- validates_formatting_of :zipcode, :using => :us_zip
136
- end
137
- ```
138
-
139
- ### US Phone numbers
140
-
141
- ```ruby
142
- class Phones < ActiveRecord::Base
143
- validates_formatting_of :phone, :using => :us_phone
144
- end
145
- ```
146
-
147
- ### IPv4
148
-
149
- ```ruby
150
- class Location < ActiveRecord::Base
151
- validates_formatting_of :ip, :using => :ip_address_v4
152
- end
153
- ```
154
-
155
- ### Social Security Number
156
-
157
- ```ruby
158
- class User < ActiveRecord::Base
159
- validates_formatting_of :ssn, :using => :ssn
160
- end
161
- ```
162
-
163
- ### Hex Colors
164
-
165
- ```ruby
166
- class Color < ActiveRecord::Base
167
- validates_formatting_of :color, :using => :hex_color
168
- end
169
- ```
107
+ class User
108
+ include ActiveModel::Validations
109
+ extend ValidatesFormattingOf::ModelAdditions
170
110
 
171
- ### Dollar Amount
111
+ attr_accessor :email
172
112
 
173
- ```ruby
174
- class Invoice < ActiveRecord::Base
175
- validates_formatting_of :amount, :using => :dollars
113
+ validates_formatting_of :email, :using => :email
176
114
  end
177
115
  ```
178
116
 
@@ -18,7 +18,7 @@ module ValidatesFormattingOf
18
18
  # (slightly revised to work on MRI 1.8.7 and ree)
19
19
  add :url, %r{\Ahttps?:\/\/([^\s:@]+:[^\s:@]*@)?[A-Za-z\d\-]+(\.[A-Za-z\d\-]+)+\.?(:\d{1,5})?([\/?]\S*)?\z}i, "is not a valid URL"
20
20
 
21
- # No numbers of symbols. allows "-"
21
+ # No numbers or symbols. allows "-"
22
22
  add :alpha, %r{\A([^\d\W]|[-])*\Z}, "must be only letters or dashes"
23
23
 
24
24
  # Letters, numbers, and spaces
@@ -1,3 +1,3 @@
1
1
  module ValidatesFormattingOf
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -6,6 +6,10 @@ if ENV["RUN_SIMPLECOV"] == 'true'
6
6
  end
7
7
  end
8
8
 
9
+ RSpec.configure do |config|
10
+ config.disable_monkey_patching!
11
+ end
12
+
9
13
  require 'validates_formatting_of'
10
14
  require 'active_model'
11
15
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ValidatesFormattingOf::ModelAdditions do
3
+ RSpec.describe ValidatesFormattingOf::ModelAdditions do
4
4
 
5
5
  describe "email" do
6
6
  class Email < TestActiveRecord
@@ -8,17 +8,17 @@ describe ValidatesFormattingOf::ModelAdditions do
8
8
  validates_formatting_of :email
9
9
  end
10
10
  it "validates that the email provided is valid" do
11
- Email.new(:email => "example@example.com").should be_valid
12
- Email.new(:email => "badexample.com").should_not be_valid
13
- Email.new(:email => "mbridges.91@gmail.com").should be_valid
14
- Email.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com").should be_valid
15
- Email.new(:email => "this__???{}|__should@be-valid.com").should be_valid
16
- Email.new(:email => "visitorservices@vmfa.museum").should be_valid
17
- Email.new(:email => "info@samoa.travel").should be_valid
18
- Email.new(:email => "info@-samoa.travel").should_not be_valid
19
- Email.new(:email => "info@samoa-.travel").should_not be_valid
20
- Email.new(:email => "info@123-samoa.travel").should be_valid
21
- Email.new(:email => "info@123-samoa.travel\n").should_not be_valid
11
+ expect(Email.new(:email => "example@example.com")).to be_valid
12
+ expect(Email.new(:email => "badexample.com")).not_to be_valid
13
+ expect(Email.new(:email => "mbridges.91@gmail.com")).to be_valid
14
+ expect(Email.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com")).to be_valid
15
+ expect(Email.new(:email => "this__???{}|__should@be-valid.com")).to be_valid
16
+ expect(Email.new(:email => "visitorservices@vmfa.museum")).to be_valid
17
+ expect(Email.new(:email => "info@samoa.travel")).to be_valid
18
+ expect(Email.new(:email => "info@-samoa.travel")).not_to be_valid
19
+ expect(Email.new(:email => "info@samoa-.travel")).not_to be_valid
20
+ expect(Email.new(:email => "info@123-samoa.travel")).to be_valid
21
+ expect(Email.new(:email => "info@123-samoa.travel\n")).not_to be_valid
22
22
  end
23
23
  end
24
24
 
@@ -28,17 +28,17 @@ describe ValidatesFormattingOf::ModelAdditions do
28
28
  validates_formatting_of :email, :using => :simple_email
29
29
  end
30
30
  it "validates that the email provided is valid" do
31
- SimpleEmail.new(:email => "example@example.com").should be_valid
32
- SimpleEmail.new(:email => "badexample.com").should_not be_valid
33
- SimpleEmail.new(:email => "mbridges.91@gmail.com").should be_valid
34
- SimpleEmail.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com").should be_valid
35
- SimpleEmail.new(:email => "this__???{}|__should@be-valid.com").should be_valid
36
- SimpleEmail.new(:email => "visitorservices@vmfa.museum").should be_valid
37
- SimpleEmail.new(:email => "info@samoa.travel").should be_valid
38
- SimpleEmail.new(:email => "info@-samoa.travel").should be_valid
39
- SimpleEmail.new(:email => "info@samoa-.travel").should be_valid
40
- SimpleEmail.new(:email => "info@123-samoa.travel").should be_valid
41
- SimpleEmail.new(:email => "info@123-samoa.travel\n").should_not be_valid
31
+ expect(SimpleEmail.new(:email => "example@example.com")).to be_valid
32
+ expect(SimpleEmail.new(:email => "badexample.com")).not_to be_valid
33
+ expect(SimpleEmail.new(:email => "mbridges.91@gmail.com")).to be_valid
34
+ expect(SimpleEmail.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com")).to be_valid
35
+ expect(SimpleEmail.new(:email => "this__???{}|__should@be-valid.com")).to be_valid
36
+ expect(SimpleEmail.new(:email => "visitorservices@vmfa.museum")).to be_valid
37
+ expect(SimpleEmail.new(:email => "info@samoa.travel")).to be_valid
38
+ expect(SimpleEmail.new(:email => "info@-samoa.travel")).to be_valid
39
+ expect(SimpleEmail.new(:email => "info@samoa-.travel")).to be_valid
40
+ expect(SimpleEmail.new(:email => "info@123-samoa.travel")).to be_valid
41
+ expect(SimpleEmail.new(:email => "info@123-samoa.travel\n")).not_to be_valid
42
42
  end
43
43
  end
44
44
  describe "url" do
@@ -47,12 +47,12 @@ describe ValidatesFormattingOf::ModelAdditions do
47
47
  validates_formatting_of :url
48
48
  end
49
49
  it "validates that the url provided is valid" do
50
- Webpage.new(:url => 'http://something.com').should be_valid
51
- Webpage.new(:url => 'http://something-else.com').should be_valid
52
- Webpage.new(:url => 'http://sub.domains.something-else.com').should be_valid
53
- Webpage.new(:url => 'http://username:password@something-else.com').should be_valid
54
- Webpage.new(:url => "http://username:password@something-else.com\n").should_not be_valid
55
- Webpage.new(:url => "something else").should_not be_valid
50
+ expect(Webpage.new(:url => 'http://something.com')).to be_valid
51
+ expect(Webpage.new(:url => 'http://something-else.com')).to be_valid
52
+ expect(Webpage.new(:url => 'http://sub.domains.something-else.com')).to be_valid
53
+ expect(Webpage.new(:url => 'http://username:password@something-else.com')).to be_valid
54
+ expect(Webpage.new(:url => "http://username:password@something-else.com\n")).not_to be_valid
55
+ expect(Webpage.new(:url => "something else")).not_to be_valid
56
56
  end
57
57
  end
58
58
 
@@ -62,12 +62,12 @@ describe ValidatesFormattingOf::ModelAdditions do
62
62
  validates_formatting_of :zipcode, :using => :us_zip
63
63
  end
64
64
  it "validates that the zipcode provided is valid" do
65
- USZip.new(:zipcode => '92348').should be_valid
66
- USZip.new(:zipcode => '23434-2348').should be_valid
67
- USZip.new(:zipcode => "23434-2348\n").should_not be_valid
68
- USZip.new(:zipcode => '234').should_not be_valid
69
- USZip.new(:zipcode => '23408234').should_not be_valid
70
- USZip.new(:zipcode => 'invalid').should_not be_valid
65
+ expect(USZip.new(:zipcode => '92348')).to be_valid
66
+ expect(USZip.new(:zipcode => '23434-2348')).to be_valid
67
+ expect(USZip.new(:zipcode => "23434-2348\n")).not_to be_valid
68
+ expect(USZip.new(:zipcode => '234')).not_to be_valid
69
+ expect(USZip.new(:zipcode => '23408234')).not_to be_valid
70
+ expect(USZip.new(:zipcode => 'invalid')).not_to be_valid
71
71
  end
72
72
  end
73
73
 
@@ -77,10 +77,10 @@ describe ValidatesFormattingOf::ModelAdditions do
77
77
  validates_formatting_of :alpha
78
78
  end
79
79
  it "validates that the letters provided is valid" do
80
- Alpha.new(:alpha => 'abscdsofjsdpfahdsofkajlsdfaspdhjfads').should be_valid
81
- Alpha.new(:alpha => 'asdfalskdfjhas-dlfhasdksdfaldhfadsfasdfa').should be_valid
82
- Alpha.new(:alpha => 'adsufasodfksadjfskjdfha98').should_not be_valid
83
- Alpha.new(:alpha => 'asdf ausdpf98hasdfo alsdf ja8 sd').should_not be_valid
80
+ expect(Alpha.new(:alpha => 'abscdsofjsdpfahdsofkajlsdfaspdhjfads')).to be_valid
81
+ expect(Alpha.new(:alpha => 'asdfalskdfjhas-dlfhasdksdfaldhfadsfasdfa')).to be_valid
82
+ expect(Alpha.new(:alpha => 'adsufasodfksadjfskjdfha98')).not_to be_valid
83
+ expect(Alpha.new(:alpha => 'asdf ausdpf98hasdfo alsdf ja8 sd')).not_to be_valid
84
84
  end
85
85
  end
86
86
 
@@ -90,10 +90,10 @@ describe ValidatesFormattingOf::ModelAdditions do
90
90
  validates_formatting_of :letters_and_numbers, :using => :alphanum
91
91
  end
92
92
  it "validates that the letters provided is valid" do
93
- Alphanum.new(:letters_and_numbers => 'numbersandlettersarevalid1234567890').should be_valid
94
- Alphanum.new(:letters_and_numbers => 'justletters').should be_valid
95
- Alphanum.new(:letters_and_numbers => 'letters and numbers 123 with spaces').should be_valid
96
- Alphanum.new(:letters_and_numbers => 'adding ; some special ** chars').should_not be_valid
93
+ expect(Alphanum.new(:letters_and_numbers => 'numbersandlettersarevalid1234567890')).to be_valid
94
+ expect(Alphanum.new(:letters_and_numbers => 'justletters')).to be_valid
95
+ expect(Alphanum.new(:letters_and_numbers => 'letters and numbers 123 with spaces')).to be_valid
96
+ expect(Alphanum.new(:letters_and_numbers => 'adding ; some special ** chars')).not_to be_valid
97
97
  end
98
98
  end
99
99
 
@@ -103,14 +103,14 @@ describe ValidatesFormattingOf::ModelAdditions do
103
103
  validates_formatting_of :phone_number, :using => :us_phone
104
104
  end
105
105
  it "validates that the phone number provided is valid" do
106
- USPhone.new(:phone_number => '(234) 234-3456').should be_valid
107
- USPhone.new(:phone_number => '123 123 3456').should be_valid
108
- USPhone.new(:phone_number => '1231233456').should be_valid
109
- USPhone.new(:phone_number => '123.123.3456').should be_valid
110
- USPhone.new(:phone_number => '(223)123-2347').should be_valid
111
- USPhone.new(:phone_number => "(223)123-2347\n").should_not be_valid
112
- USPhone.new(:phone_number => '(223 123-2347').should_not be_valid
113
- USPhone.new(:phone_number => '12349870238').should_not be_valid
106
+ expect(USPhone.new(:phone_number => '(234) 234-3456')).to be_valid
107
+ expect(USPhone.new(:phone_number => '123 123 3456')).to be_valid
108
+ expect(USPhone.new(:phone_number => '1231233456')).to be_valid
109
+ expect(USPhone.new(:phone_number => '123.123.3456')).to be_valid
110
+ expect(USPhone.new(:phone_number => '(223)123-2347')).to be_valid
111
+ expect(USPhone.new(:phone_number => "(223)123-2347\n")).not_to be_valid
112
+ expect(USPhone.new(:phone_number => '(223 123-2347')).not_to be_valid
113
+ expect(USPhone.new(:phone_number => '12349870238')).not_to be_valid
114
114
  end
115
115
  end
116
116
 
@@ -120,13 +120,13 @@ describe ValidatesFormattingOf::ModelAdditions do
120
120
  validates_formatting_of :ipv4, :using => :ip_address_v4
121
121
  end
122
122
  it "validates that the IP address provided is valid" do
123
- IPAddress.new(:ipv4 => '10.10.10').should_not be_valid
124
- IPAddress.new(:ipv4 => '999.10.10.20').should_not be_valid
125
- IPAddress.new(:ipv4 => '2222.22.22.22').should_not be_valid
126
- IPAddress.new(:ipv4 => '22.2222.22.2').should_not be_valid
127
- IPAddress.new(:ipv4 => '127.0.0.1').should be_valid
128
- IPAddress.new(:ipv4 => '132.254.111.10').should be_valid
129
- IPAddress.new(:ipv4 => "132.254.111.10\n").should_not be_valid
123
+ expect(IPAddress.new(:ipv4 => '10.10.10')).not_to be_valid
124
+ expect(IPAddress.new(:ipv4 => '999.10.10.20')).not_to be_valid
125
+ expect(IPAddress.new(:ipv4 => '2222.22.22.22')).not_to be_valid
126
+ expect(IPAddress.new(:ipv4 => '22.2222.22.2')).not_to be_valid
127
+ expect(IPAddress.new(:ipv4 => '127.0.0.1')).to be_valid
128
+ expect(IPAddress.new(:ipv4 => '132.254.111.10')).to be_valid
129
+ expect(IPAddress.new(:ipv4 => "132.254.111.10\n")).not_to be_valid
130
130
  end
131
131
  end
132
132
 
@@ -138,11 +138,11 @@ describe ValidatesFormattingOf::ModelAdditions do
138
138
  validates_formatting_of :cc, :using => :credit_card
139
139
  end
140
140
  it "validates that the credit card number provided is valid" do
141
- Client.new(:cc => '4264-2879-1230-0000').should be_valid # Visa style
142
- Client.new(:cc => '6011-1111-0000-2391').should be_valid # Discover style
143
- Client.new(:cc => '5422434400828888').should be_valid # Mastercard style
144
- Client.new(:cc => "5422434400828889\n").should_not be_valid # Mastercard style
145
- Client.new(:cc => '1233444444444444').should_not be_valid # fake
141
+ expect(Client.new(:cc => '4264-2879-1230-0000')).to be_valid # Visa style
142
+ expect(Client.new(:cc => '6011-1111-0000-2391')).to be_valid # Discover style
143
+ expect(Client.new(:cc => '5422434400828888')).to be_valid # Mastercard style
144
+ expect(Client.new(:cc => "5422434400828889\n")).not_to be_valid # Mastercard style
145
+ expect(Client.new(:cc => '1233444444444444')).not_to be_valid # fake
146
146
  end
147
147
  end
148
148
 
@@ -152,13 +152,13 @@ describe ValidatesFormattingOf::ModelAdditions do
152
152
  validates_formatting_of :ssn
153
153
  end
154
154
  it "validates that the social security number provided is valid" do
155
- AnotherPerson.new(:ssn => "145.47.0191").should be_valid
156
- AnotherPerson.new(:ssn => "223-43-2343").should be_valid
157
- AnotherPerson.new(:ssn => "999.55.8888").should be_valid
158
- AnotherPerson.new(:ssn => "999.55.8888\n").should_not be_valid
159
- AnotherPerson.new(:ssn => "28934").should_not be_valid
160
- AnotherPerson.new(:ssn => "228934828934934").should_not be_valid
161
- AnotherPerson.new(:ssn => "23498.7234").should_not be_valid
155
+ expect(AnotherPerson.new(:ssn => "145.47.0191")).to be_valid
156
+ expect(AnotherPerson.new(:ssn => "223-43-2343")).to be_valid
157
+ expect(AnotherPerson.new(:ssn => "999.55.8888")).to be_valid
158
+ expect(AnotherPerson.new(:ssn => "999.55.8888\n")).not_to be_valid
159
+ expect(AnotherPerson.new(:ssn => "28934")).not_to be_valid
160
+ expect(AnotherPerson.new(:ssn => "228934828934934")).not_to be_valid
161
+ expect(AnotherPerson.new(:ssn => "23498.7234")).not_to be_valid
162
162
  end
163
163
  end
164
164
 
@@ -168,16 +168,16 @@ describe ValidatesFormattingOf::ModelAdditions do
168
168
  validates_formatting_of :color, :using => :hex_color
169
169
  end
170
170
  it "validates that the hex color value provided is valid" do
171
- Color.new(:color => "efefef").should be_valid
172
- Color.new(:color => "98de89").should be_valid
173
- Color.new(:color => "000011").should be_valid
174
- Color.new(:color => "132").should be_valid
175
- Color.new(:color => "eef").should be_valid
176
- Color.new(:color => "eef\n").should_not be_valid
177
- Color.new(:color => "efefe").should_not be_valid
178
- Color.new(:color => "zsdfsd").should_not be_valid
179
- Color.new(:color => "p98hul;").should_not be_valid
180
- Color.new(:color => "sdfsdfsf").should_not be_valid
171
+ expect(Color.new(:color => "efefef")).to be_valid
172
+ expect(Color.new(:color => "98de89")).to be_valid
173
+ expect(Color.new(:color => "000011")).to be_valid
174
+ expect(Color.new(:color => "132")).to be_valid
175
+ expect(Color.new(:color => "eef")).to be_valid
176
+ expect(Color.new(:color => "eef\n")).not_to be_valid
177
+ expect(Color.new(:color => "efefe")).not_to be_valid
178
+ expect(Color.new(:color => "zsdfsd")).not_to be_valid
179
+ expect(Color.new(:color => "p98hul;")).not_to be_valid
180
+ expect(Color.new(:color => "sdfsdfsf")).not_to be_valid
181
181
  end
182
182
  end
183
183
 
@@ -189,9 +189,9 @@ describe ValidatesFormattingOf::ModelAdditions do
189
189
  end
190
190
  it "validates the phone formatting only on creation" do
191
191
  option = Phony.new(:phone => "(123) 234-4567")
192
- option.should be_valid
192
+ expect(option).to be_valid
193
193
  option.phone = "123123123"
194
- option.should be_valid
194
+ expect(option).to be_valid
195
195
  end
196
196
 
197
197
  class Iffy < TestActiveRecord
@@ -200,8 +200,8 @@ describe ValidatesFormattingOf::ModelAdditions do
200
200
  validates_formatting_of :phone, :using => :us_phone, :if => lambda { |iffy| iffy.name == "Matthew" }
201
201
  end
202
202
  it "validates the phone formatting only if a name is specified" do
203
- Iffy.new(:phone => "(123 345-4567", :name => "Bill").should be_valid
204
- Iffy.new(:phone => "(123 345-4567", :name => "Matthew").should_not be_valid
203
+ expect(Iffy.new(:phone => "(123 345-4567", :name => "Bill")).to be_valid
204
+ expect(Iffy.new(:phone => "(123 345-4567", :name => "Matthew")).not_to be_valid
205
205
  end
206
206
 
207
207
  class Unlessy < TestActiveRecord
@@ -210,8 +210,8 @@ describe ValidatesFormattingOf::ModelAdditions do
210
210
  validates_formatting_of :phone, :using => :us_phone, :unless => lambda { |unlessy| unlessy.name == "Matthew" }
211
211
  end
212
212
  it "validates the phone formatting only if a name is specified" do
213
- Unlessy.new(:phone => "(123 345-4567", :name => "Bill").should_not be_valid
214
- Unlessy.new(:phone => "(123 345-4567", :name => "Matthew").should be_valid
213
+ expect(Unlessy.new(:phone => "(123 345-4567", :name => "Bill")).not_to be_valid
214
+ expect(Unlessy.new(:phone => "(123 345-4567", :name => "Matthew")).to be_valid
215
215
  end
216
216
  end
217
217
  describe "dollars" do
@@ -220,15 +220,15 @@ describe ValidatesFormattingOf::ModelAdditions do
220
220
  validates_formatting_of :amount, :using => :dollars
221
221
  end
222
222
  it "validates that the dollars amount provided is valid" do
223
- Money.new(:amount => "$100.00").should be_valid
224
- Money.new(:amount => "100.00").should be_valid
225
- Money.new(:amount => "12,234,343").should be_valid
226
- Money.new(:amount => "$12.34").should be_valid
227
- Money.new(:amount => "120,123,232.32").should be_valid
228
- Money.new(:amount => "$$1111111100").should_not be_valid
229
- Money.new(:amount => "100;00").should_not be_valid
230
- Money.new(:amount => "238,3423,42..99").should_not be_valid
231
- Money.new(:amount => "$-233").should_not be_valid
223
+ expect(Money.new(:amount => "$100.00")).to be_valid
224
+ expect(Money.new(:amount => "100.00")).to be_valid
225
+ expect(Money.new(:amount => "12,234,343")).to be_valid
226
+ expect(Money.new(:amount => "$12.34")).to be_valid
227
+ expect(Money.new(:amount => "120,123,232.32")).to be_valid
228
+ expect(Money.new(:amount => "$$1111111100")).not_to be_valid
229
+ expect(Money.new(:amount => "100;00")).not_to be_valid
230
+ expect(Money.new(:amount => "238,3423,42..99")).not_to be_valid
231
+ expect(Money.new(:amount => "$-233")).not_to be_valid
232
232
  end
233
233
  end
234
234
  describe "custom messages" do
@@ -238,9 +238,9 @@ describe ValidatesFormattingOf::ModelAdditions do
238
238
  end
239
239
  it "are allowed and can be used in displaying error messages" do
240
240
  message = Message.new(:first_name => "invalid-first-name-123")
241
- message.should_not be_valid
242
- message.errors.keys.class.should eq Array
243
- message.errors.full_messages.first.should =~ /is not a valid first name/
241
+ expect(message).not_to be_valid
242
+ expect(message.errors.keys.class).to eq Array
243
+ expect(message.errors.full_messages.first).to match(/is not a valid first name/)
244
244
  end
245
245
  end
246
246
 
@@ -251,11 +251,11 @@ describe ValidatesFormattingOf::ModelAdditions do
251
251
  end
252
252
  it "set a default error" do
253
253
  problems = Problems.new(:name => "sdfs12312dfsd")
254
- problems.should_not be_valid
255
- problems.errors.full_messages.first.should =~ /letters/i
254
+ expect(problems).not_to be_valid
255
+ expect(problems.errors.full_messages.first).to match(/letters/i)
256
256
  email = Email.new(:email => "not.an.email.address")
257
- email.should_not be_valid
258
- email.errors.full_messages.first.should =~ /email/i
257
+ expect(email).not_to be_valid
258
+ expect(email.errors.full_messages.first).to match(/email/i)
259
259
  end
260
260
  end
261
261
 
@@ -269,13 +269,13 @@ describe ValidatesFormattingOf::ModelAdditions do
269
269
  let(:people) { PeopleTest.new(:email => "mbridges.91@gmail.com", :email2 => "mbridges.91@gmail.com", :email3 => "mbridges.91@gmail.com") }
270
270
  it "should test nil and blank values correctly" do
271
271
  people.email = nil
272
- people.should be_valid
272
+ expect(people).to be_valid
273
273
  people.email = "mbridges.91@gmail.com"
274
274
  people.email2 = ""
275
- people.should be_valid
275
+ expect(people).to be_valid
276
276
  people.email2 = "mbridges.91@gmail.com"
277
277
  people.email3 = nil
278
- people.should_not be_valid
278
+ expect(people).not_to be_valid
279
279
  end
280
280
  end
281
281
 
@@ -1,4 +1,5 @@
1
1
  require 'validates_formatting_of/validation_addition'
2
+ require 'its'
2
3
 
3
4
  module ValidatesFormattingOf
4
5
 
@@ -9,43 +10,43 @@ module ValidatesFormattingOf
9
10
  end
10
11
  end
11
12
 
12
- describe ValidationAddition do
13
+ RSpec.describe ValidationAddition do
13
14
  before do
14
15
  TestAdding.clear!
15
16
  TestAdding.add :email, /email/i
16
17
  end
17
18
  it "should be able to add new validations" do
18
19
  TestAdding.add :another, /another/i
19
- TestAdding.validations.count.should == 2
20
- TestAdding.validations['email'].should be_instance_of Validation
21
- TestAdding.validations['another'].should be_instance_of Validation
20
+ expect(TestAdding.validations.count).to eq(2)
21
+ expect(TestAdding.validations['email']).to be_instance_of Validation
22
+ expect(TestAdding.validations['another']).to be_instance_of Validation
22
23
  end
23
24
  describe "find" do
24
25
  context "implicit validation method" do
25
26
  subject { TestAdding.find(:email) }
26
- its(:name) { should == :email }
27
- its(:regex) { should == /email/i }
27
+ its(:name) { is_expected.to eq(:email) }
28
+ its(:regex) { is_expected.to eq(/email/i) }
28
29
  end
29
30
  context "explicit validation method" do
30
31
  subject { TestAdding.find(:non_existent_validation, :using => :email) }
31
- its(:name) { should == :email }
32
- its(:regex) { should == /email/i }
32
+ its(:name) { is_expected.to eq(:email) }
33
+ its(:regex) { is_expected.to eq(/email/i) }
33
34
  end
34
35
  end
35
36
  it "should raise an error if the method does not exist" do
36
37
  expect { TestAdding.find(:fake) }.to raise_error MissingValidation
37
38
  end
38
39
  it "should be able to determine if the method does not exist" do
39
- TestAdding.exists?(:email).should be_true
40
- TestAdding.exists?(:non_existent).should be_false
40
+ expect(TestAdding.exists?(:email)).to be_truthy
41
+ expect(TestAdding.exists?(:non_existent)).to be_falsey
41
42
  end
42
43
  it "should be able to accept strings for validation names (for namespacing)" do
43
44
  TestAdding.add "namespace:phone", /namespace/i
44
- TestAdding.exists?("namespace:phone").should be_true
45
+ expect(TestAdding.exists?("namespace:phone")).to be_truthy
45
46
  end
46
47
  it "should be able to determine if the method is missing" do
47
- TestAdding.missing?(:non_existent).should be_true
48
- TestAdding.missing?(:email).should be_false
48
+ expect(TestAdding.missing?(:non_existent)).to be_truthy
49
+ expect(TestAdding.missing?(:email)).to be_falsey
49
50
  end
50
51
  end
51
52
  end
@@ -1,18 +1,19 @@
1
1
  require 'validates_formatting_of/validation'
2
+ require 'its'
2
3
 
3
4
  module ValidatesFormattingOf
4
5
 
5
- describe Validation do
6
+ RSpec.describe Validation do
6
7
  context "valid validation creation" do
7
8
  let(:validation) { Validation.new(:name, /something/i, "is an invalid value") }
8
9
  subject { validation }
9
- its(:name) { should == :name }
10
- its(:regex) { should == %r{something}i }
11
- its(:message) { should == 'is an invalid value' }
12
- its(:to_s) { should == "<Validation::name>" }
13
- its(:inspect) { should =~ /Validation/ }
14
- its(:inspect) { should =~ /\/something\/i/ }
15
- its(:inspect) { should =~ /\:name/ }
10
+ its(:name) { is_expected.to eq(:name) }
11
+ its(:regex) { is_expected.to eq(%r{something}i) }
12
+ its(:message) { is_expected.to eq('is an invalid value') }
13
+ its(:to_s) { is_expected.to eq("<Validation::name>") }
14
+ its(:inspect) { is_expected.to match(/Validation/) }
15
+ its(:inspect) { is_expected.to match(/\/something\/i/) }
16
+ its(:inspect) { is_expected.to match(/\:name/) }
16
17
  end
17
18
  context "invalid validation creation" do
18
19
  it "should raise an error if the specified regex is not a Regexp objct" do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ValidatesFormattingOf::Validations do
3
+ RSpec.describe ValidatesFormattingOf::Validations do
4
4
 
5
5
  describe "with 'sexy' validation style" do
6
6
  describe "email" do
@@ -10,17 +10,17 @@ describe ValidatesFormattingOf::Validations do
10
10
  end
11
11
 
12
12
  it "validates that the email provided is valid" do
13
- Email.new(:email => "example@example.com").should be_valid
14
- Email.new(:email => "badexample.com").should_not be_valid
15
- Email.new(:email => "mbridges.91@gmail.com").should be_valid
16
- Email.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com").should be_valid
17
- Email.new(:email => "this__???{}|__should@be-valid.com").should be_valid
18
- Email.new(:email => "visitorservices@vmfa.museum").should be_valid
19
- Email.new(:email => "info@samoa.travel").should be_valid
20
- Email.new(:email => "info@-samoa.travel").should_not be_valid
21
- Email.new(:email => "info@samoa-.travel").should_not be_valid
22
- Email.new(:email => "info@123-samoa.travel").should be_valid
23
- Email.new(:email => "info@123-samoa.travel\n").should_not be_valid
13
+ expect(Email.new(:email => "example@example.com")).to be_valid
14
+ expect(Email.new(:email => "badexample.com")).not_to be_valid
15
+ expect(Email.new(:email => "mbridges.91@gmail.com")).to be_valid
16
+ expect(Email.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com")).to be_valid
17
+ expect(Email.new(:email => "this__???{}|__should@be-valid.com")).to be_valid
18
+ expect(Email.new(:email => "visitorservices@vmfa.museum")).to be_valid
19
+ expect(Email.new(:email => "info@samoa.travel")).to be_valid
20
+ expect(Email.new(:email => "info@-samoa.travel")).not_to be_valid
21
+ expect(Email.new(:email => "info@samoa-.travel")).not_to be_valid
22
+ expect(Email.new(:email => "info@123-samoa.travel")).to be_valid
23
+ expect(Email.new(:email => "info@123-samoa.travel\n")).not_to be_valid
24
24
  end
25
25
  end
26
26
 
@@ -30,17 +30,17 @@ describe ValidatesFormattingOf::Validations do
30
30
  validates :email, :simple_email => true
31
31
  end
32
32
  it "validates that the email provided is valid" do
33
- SimpleEmail.new(:email => "example@example.com").should be_valid
34
- SimpleEmail.new(:email => "badexample.com").should_not be_valid
35
- SimpleEmail.new(:email => "mbridges.91@gmail.com").should be_valid
36
- SimpleEmail.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com").should be_valid
37
- SimpleEmail.new(:email => "this__???{}|__should@be-valid.com").should be_valid
38
- SimpleEmail.new(:email => "visitorservices@vmfa.museum").should be_valid
39
- SimpleEmail.new(:email => "info@samoa.travel").should be_valid
40
- SimpleEmail.new(:email => "info@-samoa.travel").should be_valid
41
- SimpleEmail.new(:email => "info@samoa-.travel").should be_valid
42
- SimpleEmail.new(:email => "info@123-samoa.travel").should be_valid
43
- SimpleEmail.new(:email => "info@123-samoa.travel\n").should_not be_valid
33
+ expect(SimpleEmail.new(:email => "example@example.com")).to be_valid
34
+ expect(SimpleEmail.new(:email => "badexample.com")).not_to be_valid
35
+ expect(SimpleEmail.new(:email => "mbridges.91@gmail.com")).to be_valid
36
+ expect(SimpleEmail.new(:email => "some-random%%%strangely-formatted-email@lots.of.subdomains.com")).to be_valid
37
+ expect(SimpleEmail.new(:email => "this__???{}|__should@be-valid.com")).to be_valid
38
+ expect(SimpleEmail.new(:email => "visitorservices@vmfa.museum")).to be_valid
39
+ expect(SimpleEmail.new(:email => "info@samoa.travel")).to be_valid
40
+ expect(SimpleEmail.new(:email => "info@-samoa.travel")).to be_valid
41
+ expect(SimpleEmail.new(:email => "info@samoa-.travel")).to be_valid
42
+ expect(SimpleEmail.new(:email => "info@123-samoa.travel")).to be_valid
43
+ expect(SimpleEmail.new(:email => "info@123-samoa.travel\n")).not_to be_valid
44
44
  end
45
45
  end
46
46
  describe "url" do
@@ -49,12 +49,12 @@ describe ValidatesFormattingOf::Validations do
49
49
  validates :url, :url => true
50
50
  end
51
51
  it "validates that the url provided is valid" do
52
- Webpage.new(:url => 'http://something.com').should be_valid
53
- Webpage.new(:url => 'http://something-else.com').should be_valid
54
- Webpage.new(:url => 'http://sub.domains.something-else.com').should be_valid
55
- Webpage.new(:url => 'http://username:password@something-else.com').should be_valid
56
- Webpage.new(:url => "http://username:password@something-else.com\n").should_not be_valid
57
- Webpage.new(:url => "something else").should_not be_valid
52
+ expect(Webpage.new(:url => 'http://something.com')).to be_valid
53
+ expect(Webpage.new(:url => 'http://something-else.com')).to be_valid
54
+ expect(Webpage.new(:url => 'http://sub.domains.something-else.com')).to be_valid
55
+ expect(Webpage.new(:url => 'http://username:password@something-else.com')).to be_valid
56
+ expect(Webpage.new(:url => "http://username:password@something-else.com\n")).not_to be_valid
57
+ expect(Webpage.new(:url => "something else")).not_to be_valid
58
58
  end
59
59
  end
60
60
 
@@ -64,12 +64,12 @@ describe ValidatesFormattingOf::Validations do
64
64
  validates :zipcode, :us_zip => true
65
65
  end
66
66
  it "validates that the zipcode provided is valid" do
67
- USZip.new(:zipcode => '92348').should be_valid
68
- USZip.new(:zipcode => '23434-2348').should be_valid
69
- USZip.new(:zipcode => "23434-2348\n").should_not be_valid
70
- USZip.new(:zipcode => '234').should_not be_valid
71
- USZip.new(:zipcode => '23408234').should_not be_valid
72
- USZip.new(:zipcode => 'invalid').should_not be_valid
67
+ expect(USZip.new(:zipcode => '92348')).to be_valid
68
+ expect(USZip.new(:zipcode => '23434-2348')).to be_valid
69
+ expect(USZip.new(:zipcode => "23434-2348\n")).not_to be_valid
70
+ expect(USZip.new(:zipcode => '234')).not_to be_valid
71
+ expect(USZip.new(:zipcode => '23408234')).not_to be_valid
72
+ expect(USZip.new(:zipcode => 'invalid')).not_to be_valid
73
73
  end
74
74
  end
75
75
 
@@ -79,10 +79,10 @@ describe ValidatesFormattingOf::Validations do
79
79
  validates :alpha, :alpha => true
80
80
  end
81
81
  it "validates that the letters provided is valid" do
82
- Alpha.new(:alpha => 'abscdsofjsdpfahdsofkajlsdfaspdhjfads').should be_valid
83
- Alpha.new(:alpha => 'asdfalskdfjhas-dlfhasdksdfaldhfadsfasdfa').should be_valid
84
- Alpha.new(:alpha => 'adsufasodfksadjfskjdfha98').should_not be_valid
85
- Alpha.new(:alpha => 'asdf ausdpf98hasdfo alsdf ja8 sd').should_not be_valid
82
+ expect(Alpha.new(:alpha => 'abscdsofjsdpfahdsofkajlsdfaspdhjfads')).to be_valid
83
+ expect(Alpha.new(:alpha => 'asdfalskdfjhas-dlfhasdksdfaldhfadsfasdfa')).to be_valid
84
+ expect(Alpha.new(:alpha => 'adsufasodfksadjfskjdfha98')).not_to be_valid
85
+ expect(Alpha.new(:alpha => 'asdf ausdpf98hasdfo alsdf ja8 sd')).not_to be_valid
86
86
  end
87
87
  end
88
88
 
@@ -92,10 +92,10 @@ describe ValidatesFormattingOf::Validations do
92
92
  validates :letters_and_numbers, :alphanum => true
93
93
  end
94
94
  it "validates that the letters provided is valid" do
95
- Alphanum.new(:letters_and_numbers => 'numbersandlettersarevalid1234567890').should be_valid
96
- Alphanum.new(:letters_and_numbers => 'justletters').should be_valid
97
- Alphanum.new(:letters_and_numbers => 'letters and numbers 123 with spaces').should be_valid
98
- Alphanum.new(:letters_and_numbers => 'adding ; some special ** chars').should_not be_valid
95
+ expect(Alphanum.new(:letters_and_numbers => 'numbersandlettersarevalid1234567890')).to be_valid
96
+ expect(Alphanum.new(:letters_and_numbers => 'justletters')).to be_valid
97
+ expect(Alphanum.new(:letters_and_numbers => 'letters and numbers 123 with spaces')).to be_valid
98
+ expect(Alphanum.new(:letters_and_numbers => 'adding ; some special ** chars')).not_to be_valid
99
99
  end
100
100
  end
101
101
 
@@ -105,14 +105,14 @@ describe ValidatesFormattingOf::Validations do
105
105
  validates :phone_number, :us_phone => true
106
106
  end
107
107
  it "validates that the phone number provided is valid" do
108
- USPhone.new(:phone_number => '(234) 234-3456').should be_valid
109
- USPhone.new(:phone_number => '123 123 3456').should be_valid
110
- USPhone.new(:phone_number => '1231233456').should be_valid
111
- USPhone.new(:phone_number => '123.123.3456').should be_valid
112
- USPhone.new(:phone_number => '(223)123-2347').should be_valid
113
- USPhone.new(:phone_number => "(223)123-2347\n").should_not be_valid
114
- USPhone.new(:phone_number => '(223 123-2347').should_not be_valid
115
- USPhone.new(:phone_number => '12349870238').should_not be_valid
108
+ expect(USPhone.new(:phone_number => '(234) 234-3456')).to be_valid
109
+ expect(USPhone.new(:phone_number => '123 123 3456')).to be_valid
110
+ expect(USPhone.new(:phone_number => '1231233456')).to be_valid
111
+ expect(USPhone.new(:phone_number => '123.123.3456')).to be_valid
112
+ expect(USPhone.new(:phone_number => '(223)123-2347')).to be_valid
113
+ expect(USPhone.new(:phone_number => "(223)123-2347\n")).not_to be_valid
114
+ expect(USPhone.new(:phone_number => '(223 123-2347')).not_to be_valid
115
+ expect(USPhone.new(:phone_number => '12349870238')).not_to be_valid
116
116
  end
117
117
  end
118
118
 
@@ -122,13 +122,13 @@ describe ValidatesFormattingOf::Validations do
122
122
  validates :ipv4, :ip_address_v4 => true
123
123
  end
124
124
  it "validates that the IP address provided is valid" do
125
- IPAddress.new(:ipv4 => '10.10.10').should_not be_valid
126
- IPAddress.new(:ipv4 => '999.10.10.20').should_not be_valid
127
- IPAddress.new(:ipv4 => '2222.22.22.22').should_not be_valid
128
- IPAddress.new(:ipv4 => '22.2222.22.2').should_not be_valid
129
- IPAddress.new(:ipv4 => '127.0.0.1').should be_valid
130
- IPAddress.new(:ipv4 => '132.254.111.10').should be_valid
131
- IPAddress.new(:ipv4 => "132.254.111.10\n").should_not be_valid
125
+ expect(IPAddress.new(:ipv4 => '10.10.10')).not_to be_valid
126
+ expect(IPAddress.new(:ipv4 => '999.10.10.20')).not_to be_valid
127
+ expect(IPAddress.new(:ipv4 => '2222.22.22.22')).not_to be_valid
128
+ expect(IPAddress.new(:ipv4 => '22.2222.22.2')).not_to be_valid
129
+ expect(IPAddress.new(:ipv4 => '127.0.0.1')).to be_valid
130
+ expect(IPAddress.new(:ipv4 => '132.254.111.10')).to be_valid
131
+ expect(IPAddress.new(:ipv4 => "132.254.111.10\n")).not_to be_valid
132
132
  end
133
133
  end
134
134
 
@@ -140,11 +140,11 @@ describe ValidatesFormattingOf::Validations do
140
140
  validates :cc, :credit_card => true
141
141
  end
142
142
  it "validates that the credit card number provided is valid" do
143
- Client.new(:cc => '4264-2879-1230-0000').should be_valid # Visa style
144
- Client.new(:cc => '6011-1111-0000-2391').should be_valid # Discover style
145
- Client.new(:cc => '5422434400828888').should be_valid # Mastercard style
146
- Client.new(:cc => "5422434400828889\n").should_not be_valid # Mastercard style
147
- Client.new(:cc => '1233444444444444').should_not be_valid # fake
143
+ expect(Client.new(:cc => '4264-2879-1230-0000')).to be_valid # Visa style
144
+ expect(Client.new(:cc => '6011-1111-0000-2391')).to be_valid # Discover style
145
+ expect(Client.new(:cc => '5422434400828888')).to be_valid # Mastercard style
146
+ expect(Client.new(:cc => "5422434400828889\n")).not_to be_valid # Mastercard style
147
+ expect(Client.new(:cc => '1233444444444444')).not_to be_valid # fake
148
148
  end
149
149
  end
150
150
 
@@ -154,13 +154,13 @@ describe ValidatesFormattingOf::Validations do
154
154
  validates :ssn, :ssn => true
155
155
  end
156
156
  it "validates that the social security number provided is valid" do
157
- AnotherPerson.new(:ssn => "145.47.0191").should be_valid
158
- AnotherPerson.new(:ssn => "223-43-2343").should be_valid
159
- AnotherPerson.new(:ssn => "999.55.8888").should be_valid
160
- AnotherPerson.new(:ssn => "999.55.8888\n").should_not be_valid
161
- AnotherPerson.new(:ssn => "28934").should_not be_valid
162
- AnotherPerson.new(:ssn => "228934828934934").should_not be_valid
163
- AnotherPerson.new(:ssn => "23498.7234").should_not be_valid
157
+ expect(AnotherPerson.new(:ssn => "145.47.0191")).to be_valid
158
+ expect(AnotherPerson.new(:ssn => "223-43-2343")).to be_valid
159
+ expect(AnotherPerson.new(:ssn => "999.55.8888")).to be_valid
160
+ expect(AnotherPerson.new(:ssn => "999.55.8888\n")).not_to be_valid
161
+ expect(AnotherPerson.new(:ssn => "28934")).not_to be_valid
162
+ expect(AnotherPerson.new(:ssn => "228934828934934")).not_to be_valid
163
+ expect(AnotherPerson.new(:ssn => "23498.7234")).not_to be_valid
164
164
  end
165
165
  end
166
166
 
@@ -170,16 +170,16 @@ describe ValidatesFormattingOf::Validations do
170
170
  validates :color, :hex_color => true
171
171
  end
172
172
  it "validates that the hex color value provided is valid" do
173
- Color.new(:color => "efefef").should be_valid
174
- Color.new(:color => "98de89").should be_valid
175
- Color.new(:color => "000011").should be_valid
176
- Color.new(:color => "132").should be_valid
177
- Color.new(:color => "eef").should be_valid
178
- Color.new(:color => "eef\n").should_not be_valid
179
- Color.new(:color => "efefe").should_not be_valid
180
- Color.new(:color => "zsdfsd").should_not be_valid
181
- Color.new(:color => "p98hul;").should_not be_valid
182
- Color.new(:color => "sdfsdfsf").should_not be_valid
173
+ expect(Color.new(:color => "efefef")).to be_valid
174
+ expect(Color.new(:color => "98de89")).to be_valid
175
+ expect(Color.new(:color => "000011")).to be_valid
176
+ expect(Color.new(:color => "132")).to be_valid
177
+ expect(Color.new(:color => "eef")).to be_valid
178
+ expect(Color.new(:color => "eef\n")).not_to be_valid
179
+ expect(Color.new(:color => "efefe")).not_to be_valid
180
+ expect(Color.new(:color => "zsdfsd")).not_to be_valid
181
+ expect(Color.new(:color => "p98hul;")).not_to be_valid
182
+ expect(Color.new(:color => "sdfsdfsf")).not_to be_valid
183
183
  end
184
184
  end
185
185
 
@@ -191,9 +191,9 @@ describe ValidatesFormattingOf::Validations do
191
191
  end
192
192
  it "validates the phone formatting only on creation" do
193
193
  option = Phony.new(:phone => "(123) 234-4567")
194
- option.should be_valid
194
+ expect(option).to be_valid
195
195
  option.phone = "123123123"
196
- option.should be_valid
196
+ expect(option).to be_valid
197
197
  end
198
198
 
199
199
  class Iffy < TestActiveRecord
@@ -202,8 +202,8 @@ describe ValidatesFormattingOf::Validations do
202
202
  validates :phone, :us_phone => true, :if => lambda { |iffy| iffy.name == "Matthew" }
203
203
  end
204
204
  it "validates the phone formatting only if a name is specified" do
205
- Iffy.new(:phone => "(123 345-4567", :name => "Bill").should be_valid
206
- Iffy.new(:phone => "(123 345-4567", :name => "Matthew").should_not be_valid
205
+ expect(Iffy.new(:phone => "(123 345-4567", :name => "Bill")).to be_valid
206
+ expect(Iffy.new(:phone => "(123 345-4567", :name => "Matthew")).not_to be_valid
207
207
  end
208
208
 
209
209
  class Unlessy < TestActiveRecord
@@ -212,8 +212,8 @@ describe ValidatesFormattingOf::Validations do
212
212
  validates :phone, :us_phone => true, :unless => lambda { |unlessy| unlessy.name == "Matthew" }
213
213
  end
214
214
  it "validates the phone formatting only if a name is specified" do
215
- Unlessy.new(:phone => "(123 345-4567", :name => "Bill").should_not be_valid
216
- Unlessy.new(:phone => "(123 345-4567", :name => "Matthew").should be_valid
215
+ expect(Unlessy.new(:phone => "(123 345-4567", :name => "Bill")).not_to be_valid
216
+ expect(Unlessy.new(:phone => "(123 345-4567", :name => "Matthew")).to be_valid
217
217
  end
218
218
  end
219
219
  describe "dollars" do
@@ -222,15 +222,15 @@ describe ValidatesFormattingOf::Validations do
222
222
  validates :amount, :dollars => true
223
223
  end
224
224
  it "validates that the dollars amount provided is valid" do
225
- Money.new(:amount => "$100.00").should be_valid
226
- Money.new(:amount => "100.00").should be_valid
227
- Money.new(:amount => "12,234,343").should be_valid
228
- Money.new(:amount => "$12.34").should be_valid
229
- Money.new(:amount => "120,123,232.32").should be_valid
230
- Money.new(:amount => "$$1111111100").should_not be_valid
231
- Money.new(:amount => "100;00").should_not be_valid
232
- Money.new(:amount => "238,3423,42..99").should_not be_valid
233
- Money.new(:amount => "$-233").should_not be_valid
225
+ expect(Money.new(:amount => "$100.00")).to be_valid
226
+ expect(Money.new(:amount => "100.00")).to be_valid
227
+ expect(Money.new(:amount => "12,234,343")).to be_valid
228
+ expect(Money.new(:amount => "$12.34")).to be_valid
229
+ expect(Money.new(:amount => "120,123,232.32")).to be_valid
230
+ expect(Money.new(:amount => "$$1111111100")).not_to be_valid
231
+ expect(Money.new(:amount => "100;00")).not_to be_valid
232
+ expect(Money.new(:amount => "238,3423,42..99")).not_to be_valid
233
+ expect(Money.new(:amount => "$-233")).not_to be_valid
234
234
  end
235
235
  end
236
236
  describe "custom messages" do
@@ -240,9 +240,9 @@ describe ValidatesFormattingOf::Validations do
240
240
  end
241
241
  it "are allowed and can be used in displaying error messages" do
242
242
  message = Message.new(:first_name => "invalid-first-name-123")
243
- message.should_not be_valid
244
- message.errors.keys.class.should eq Array
245
- message.errors.full_messages.first.should =~ /is not a valid first name/
243
+ expect(message).not_to be_valid
244
+ expect(message.errors.keys.class).to eq Array
245
+ expect(message.errors.full_messages.first).to match(/is not a valid first name/)
246
246
  end
247
247
  end
248
248
 
@@ -253,11 +253,11 @@ describe ValidatesFormattingOf::Validations do
253
253
  end
254
254
  it "set a default error" do
255
255
  problems = Problems.new(:name => "sdfs12312dfsd")
256
- problems.should_not be_valid
257
- problems.errors.full_messages.first.should =~ /letters/i
256
+ expect(problems).not_to be_valid
257
+ expect(problems.errors.full_messages.first).to match(/letters/i)
258
258
  email = Email.new(:email => "not.an.email.address")
259
- email.should_not be_valid
260
- email.errors.full_messages.first.should =~ /email/i
259
+ expect(email).not_to be_valid
260
+ expect(email.errors.full_messages.first).to match(/email/i)
261
261
  end
262
262
  end
263
263
 
@@ -271,13 +271,13 @@ describe ValidatesFormattingOf::Validations do
271
271
  let(:people) { PeopleTest.new(:email => "mbridges.91@gmail.com", :email2 => "mbridges.91@gmail.com", :email3 => "mbridges.91@gmail.com") }
272
272
  it "should test nil and blank values correctly" do
273
273
  people.email = nil
274
- people.should be_valid
274
+ expect(people).to be_valid
275
275
  people.email = "mbridges.91@gmail.com"
276
276
  people.email2 = ""
277
- people.should be_valid
277
+ expect(people).to be_valid
278
278
  people.email2 = "mbridges.91@gmail.com"
279
279
  people.email3 = nil
280
- people.should_not be_valid
280
+ expect(people).not_to be_valid
281
281
  end
282
282
  end
283
283
  end
@@ -15,9 +15,10 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = ValidatesFormattingOf::VERSION
17
17
 
18
- gem.add_dependency "activemodel", "~> 4.0"
18
+ gem.add_dependency "activemodel"
19
19
 
20
20
  gem.add_development_dependency "rake"
21
21
  gem.add_development_dependency "rspec"
22
22
  gem.add_development_dependency "simplecov"
23
+ gem.add_development_dependency "its"
23
24
  end
metadata CHANGED
@@ -1,69 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_formatting_of
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Bridges
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-01 00:00:00.000000000 Z
11
+ date: 2015-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - '>='
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  description: Common Rails validations wrapped in a gem.
@@ -73,9 +87,9 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
- - .gitignore
77
- - .rspec
78
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
79
93
  - CHANGELOG.md
80
94
  - Gemfile
81
95
  - LICENSE.txt
@@ -104,17 +118,17 @@ require_paths:
104
118
  - lib
105
119
  required_ruby_version: !ruby/object:Gem::Requirement
106
120
  requirements:
107
- - - '>='
121
+ - - ">="
108
122
  - !ruby/object:Gem::Version
109
123
  version: '0'
110
124
  required_rubygems_version: !ruby/object:Gem::Requirement
111
125
  requirements:
112
- - - '>='
126
+ - - ">="
113
127
  - !ruby/object:Gem::Version
114
128
  version: '0'
115
129
  requirements: []
116
130
  rubyforge_project:
117
- rubygems_version: 2.1.1
131
+ rubygems_version: 2.4.5
118
132
  signing_key:
119
133
  specification_version: 4
120
134
  summary: Adds several convenient methods to validate things such as emails, urls,
@@ -125,4 +139,3 @@ test_files:
125
139
  - spec/validates_formatting_of/validation_addition_spec.rb
126
140
  - spec/validates_formatting_of/validation_spec.rb
127
141
  - spec/validates_formatting_of/validator_spec.rb
128
- has_rdoc: