yukonisuru 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +4 -0
  5. data/.travis.yml +13 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +1101 -0
  9. data/Rakefile +1 -0
  10. data/config/locales/en.yml +113 -0
  11. data/lib/yukonisuru.rb +93 -0
  12. data/lib/yukonisuru/matchers/ensure_valid_alpha_format_of.rb +26 -0
  13. data/lib/yukonisuru/matchers/ensure_valid_alpha_numeric_format_of.rb +26 -0
  14. data/lib/yukonisuru/matchers/ensure_valid_base64_format_of.rb +26 -0
  15. data/lib/yukonisuru/matchers/ensure_valid_boolean_format_of.rb +26 -0
  16. data/lib/yukonisuru/matchers/ensure_valid_credit_card_format_of.rb +26 -0
  17. data/lib/yukonisuru/matchers/ensure_valid_currency_format_of.rb +26 -0
  18. data/lib/yukonisuru/matchers/ensure_valid_cusip_format_of.rb +26 -0
  19. data/lib/yukonisuru/matchers/ensure_valid_email_format_of.rb +26 -0
  20. data/lib/yukonisuru/matchers/ensure_valid_equality_matcher_of.rb +40 -0
  21. data/lib/yukonisuru/matchers/ensure_valid_gtin_format_of.rb +26 -0
  22. data/lib/yukonisuru/matchers/ensure_valid_hex_format_of.rb +26 -0
  23. data/lib/yukonisuru/matchers/ensure_valid_imei_format_of.rb +26 -0
  24. data/lib/yukonisuru/matchers/ensure_valid_ip_format_of.rb +26 -0
  25. data/lib/yukonisuru/matchers/ensure_valid_isbn_format_of.rb +26 -0
  26. data/lib/yukonisuru/matchers/ensure_valid_isin_format_of.rb +26 -0
  27. data/lib/yukonisuru/matchers/ensure_valid_latitude_format_of.rb +26 -0
  28. data/lib/yukonisuru/matchers/ensure_valid_longitude_format_of.rb +26 -0
  29. data/lib/yukonisuru/matchers/ensure_valid_mac_address_format_of.rb +26 -0
  30. data/lib/yukonisuru/matchers/ensure_valid_name_format_of.rb +26 -0
  31. data/lib/yukonisuru/matchers/ensure_valid_password_format_of.rb +26 -0
  32. data/lib/yukonisuru/matchers/ensure_valid_phone_format_of.rb +26 -0
  33. data/lib/yukonisuru/matchers/ensure_valid_sedol_format_of.rb +26 -0
  34. data/lib/yukonisuru/matchers/ensure_valid_slug_format_of.rb +26 -0
  35. data/lib/yukonisuru/matchers/ensure_valid_ssn_format_of.rb +26 -0
  36. data/lib/yukonisuru/matchers/ensure_valid_url_format_of.rb +26 -0
  37. data/lib/yukonisuru/matchers/ensure_valid_username_format_of.rb +26 -0
  38. data/lib/yukonisuru/matchers/ensure_valid_uuid_format_of.rb +26 -0
  39. data/lib/yukonisuru/validators/alpha_numeric_validator.rb +31 -0
  40. data/lib/yukonisuru/validators/alpha_validator.rb +31 -0
  41. data/lib/yukonisuru/validators/base64_validator.rb +9 -0
  42. data/lib/yukonisuru/validators/boolean_validator.rb +9 -0
  43. data/lib/yukonisuru/validators/credit_card_validator.rb +133 -0
  44. data/lib/yukonisuru/validators/currency_validator.rb +23 -0
  45. data/lib/yukonisuru/validators/cusip_validator.rb +33 -0
  46. data/lib/yukonisuru/validators/email_validator.rb +25 -0
  47. data/lib/yukonisuru/validators/equality_validator.rb +27 -0
  48. data/lib/yukonisuru/validators/gtin_validator.rb +59 -0
  49. data/lib/yukonisuru/validators/hex_validator.rb +9 -0
  50. data/lib/yukonisuru/validators/imei_validator.rb +37 -0
  51. data/lib/yukonisuru/validators/ip_validator.rb +9 -0
  52. data/lib/yukonisuru/validators/isbn_validator.rb +24 -0
  53. data/lib/yukonisuru/validators/isin_validator.rb +38 -0
  54. data/lib/yukonisuru/validators/latitude_validator.rb +9 -0
  55. data/lib/yukonisuru/validators/longitude_validator.rb +9 -0
  56. data/lib/yukonisuru/validators/mac_address_validator.rb +24 -0
  57. data/lib/yukonisuru/validators/name_validator.rb +9 -0
  58. data/lib/yukonisuru/validators/password_validator.rb +23 -0
  59. data/lib/yukonisuru/validators/phone_validator.rb +9 -0
  60. data/lib/yukonisuru/validators/sedol_validator.rb +32 -0
  61. data/lib/yukonisuru/validators/slug_validator.rb +9 -0
  62. data/lib/yukonisuru/validators/ssn_validator.rb +9 -0
  63. data/lib/yukonisuru/validators/url_validator.rb +36 -0
  64. data/lib/yukonisuru/validators/username_validator.rb +9 -0
  65. data/lib/yukonisuru/validators/uuid_validator.rb +28 -0
  66. data/lib/yukonisuru/version.rb +3 -0
  67. data/spec/lib/alpha_numeric_validator_spec.rb +91 -0
  68. data/spec/lib/alpha_validator_spec.rb +182 -0
  69. data/spec/lib/base64_validator_spec.rb +33 -0
  70. data/spec/lib/boolean_validator_spec.rb +35 -0
  71. data/spec/lib/credit_card_validator_spec.rb +686 -0
  72. data/spec/lib/currency_validator_spec.rb +63 -0
  73. data/spec/lib/cusip_validator_spec.rb +27 -0
  74. data/spec/lib/email_validator_spec.rb +109 -0
  75. data/spec/lib/equality_validator_spec.rb +334 -0
  76. data/spec/lib/gtin_validator_spec.rb +101 -0
  77. data/spec/lib/hex_validator_spec.rb +73 -0
  78. data/spec/lib/imei_validator_spec.rb +41 -0
  79. data/spec/lib/ip_validator_spec.rb +33 -0
  80. data/spec/lib/isbn_validator_spec.rb +41 -0
  81. data/spec/lib/isin_validator_spec.rb +35 -0
  82. data/spec/lib/latitude_validator_spec.rb +31 -0
  83. data/spec/lib/longitude_validator_spec.rb +31 -0
  84. data/spec/lib/mac_address_validator_spec.rb +54 -0
  85. data/spec/lib/name_validator_spec.rb +39 -0
  86. data/spec/lib/password_validator_spec.rb +87 -0
  87. data/spec/lib/phone_validator_spec.rb +42 -0
  88. data/spec/lib/sedol_validator_spec.rb +31 -0
  89. data/spec/lib/slug_validator_spec.rb +41 -0
  90. data/spec/lib/ssn_validator_spec.rb +36 -0
  91. data/spec/lib/url_validator_spec.rb +109 -0
  92. data/spec/lib/username_validator_spec.rb +37 -0
  93. data/spec/lib/uuid_validator_spec.rb +157 -0
  94. data/spec/spec_helper.rb +12 -0
  95. data/yukonisuru.gemspec +29 -0
  96. metadata +264 -0
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,113 @@
1
+ en:
2
+ yukonisuru:
3
+ errors:
4
+ messages:
5
+ alpha: "is not a valid alpha characters"
6
+ alpha_numeric: "is not a valid alpha-numeric characters"
7
+ base64: "is not a valid Base64 encode"
8
+ boolean: "is not a valid boolean"
9
+ credit_card: "is not a valid credit card"
10
+ currency: "is not a valid currency"
11
+ cusip: "is not a valid CUSIP"
12
+ email: "is not a valid email"
13
+ equality: "is not %{operator} %{attr}"
14
+ gtin: "is not a valid GTIN"
15
+ hex: "is not a valid hex color"
16
+ imei: "is not a valid IMEI"
17
+ ip: "is not a valid IP"
18
+ isbn: "is not a valid ISBN"
19
+ isin: "is not a valid ISIN"
20
+ longitude: "is not a valid latitude"
21
+ longitude: "is not a valid longitude"
22
+ mac_address: "is not a valid MAC address"
23
+ name: "is not a valid name"
24
+ password: "is not a valid password"
25
+ phone: "is not a valid phone number"
26
+ sedol: "is not a valid SEDOL"
27
+ slug: "is not a valid slug"
28
+ ssn: "is not a valid social security number"
29
+ url: "is not a valid URL"
30
+ username: "is not a valid username"
31
+ uuid: "is not a valid UUID"
32
+ matchers:
33
+ ensure_valid_alpha_format_of:
34
+ failure_message_for_should: "%{model} should ensure valid alpha format of attribute %{attr}"
35
+ failure_message_for_should_not: "%{model} should not ensure valid alpha format of attribute %{attr}"
36
+ ensure_valid_alpha_numeric_format_of:
37
+ failure_message_for_should: "%{model} should ensure valid alpha numeric format of attribute %{attr}"
38
+ failure_message_for_should_not: "%{model} should not ensure valid alpha numeric format of attribute %{attr}"
39
+ ensure_valid_base64_format_of:
40
+ failure_message_for_should: "%{model} should ensure valid Base64 encoded format of attribute %{attr}"
41
+ failure_message_for_should_not: "%{model} should not ensure valid Base64 encoded format of attribute %{attr}"
42
+ ensure_valid_boolean_format_of:
43
+ failure_message_for_should: "%{model} should ensure valid boolean format of attribute %{attr}"
44
+ failure_message_for_should_not: "%{model} should not ensure valid boolean format of attribute %{attr}"
45
+ ensure_valid_credit_card_format_of:
46
+ failure_message_for_should: "%{model} should ensure valid credit card format of attribute %{attr}"
47
+ failure_message_for_should_not: "%{model} should not ensure valid credit card format of attribute %{attr}"
48
+ ensure_valid_currency_format_of:
49
+ failure_message_for_should: "%{model} should ensure valid currency format of attribute %{attr}"
50
+ failure_message_for_should_not: "%{model} should not ensure valid currency format of attribute %{attr}"
51
+ ensure_valid_cusip_format_of:
52
+ failure_message_for_should: "%{model} should ensure valid CUSIP format of attribute %{attr}"
53
+ failure_message_for_should_not: "%{model} should not ensure valid CUSIP format of attribute %{attr}"
54
+ ensure_valid_email_format_of:
55
+ failure_message_for_should: "%{model} should ensure valid email format of attribute %{attr}"
56
+ failure_message_for_should_not: "%{model} should not ensure valid email format of attribute %{attr}"
57
+ ensure_valid_equality_format_of:
58
+ failure_message_for_should: "%{model} should ensure equality of %{operator} on attribute %{attr}"
59
+ failure_message_for_should_not: "%{model} should not ensure equality of %{operator} on attribute %{attr}"
60
+ ensure_valid_gtin_format_of:
61
+ failure_message_for_should: "%{model} should ensure valid GTIN format of attribute %{attr}"
62
+ failure_message_for_should_not: "%{model} should not ensure valid GTIN format of attribute %{attr}"
63
+ ensure_valid_hex_format_of:
64
+ failure_message_for_should: "%{model} should ensure valid hex format of attribute %{attr}"
65
+ failure_message_for_should_not: "%{model} should not ensure valid hex format of attribute %{attr}"
66
+ ensure_valid_imei_format_of:
67
+ failure_message_for_should: "%{model} should ensure valid IMEI address format of attribute %{attr}"
68
+ failure_message_for_should_not: "%{model} should not ensure valid IMEI address format of attribute %{attr}"
69
+ ensure_valid_ip_format_of:
70
+ failure_message_for_should: "%{model} should ensure valid IP address format of attribute %{attr}"
71
+ failure_message_for_should_not: "%{model} should not ensure valid IP address format of attribute %{attr}"
72
+ ensure_valid_isbn_format_of:
73
+ failure_message_for_should: "%{model} should ensure valid ISBN format of attribute %{attr}"
74
+ failure_message_for_should_not: "%{model} should not ensure valid ISBN format of attribute %{attr}"
75
+ ensure_valid_isin_format_of:
76
+ failure_message_for_should: "%{model} should ensure valid ISIN format of attribute %{attr}"
77
+ failure_message_for_should_not: "%{model} should not ensure valid ISIN format of attribute %{attr}"
78
+ ensure_valid_latitude_format_of:
79
+ failure_message_for_should: "%{model} should ensure valid latitude format of attribute %{attr}"
80
+ failure_message_for_should_not: "%{model} should not ensure valid latitude format of attribute %{attr}"
81
+ ensure_valid_longitude_format_of:
82
+ failure_message_for_should: "%{model} should ensure valid longitude format of attribute %{attr}"
83
+ failure_message_for_should_not: "%{model} should not ensure valid longitude format of attribute %{attr}"
84
+ ensure_valid_mac_address_format_of:
85
+ failure_message_for_should: "%{model} should ensure valid MAC address format of attribute %{attr}"
86
+ failure_message_for_should_not: "%{model} should not ensure valid MAC address format of attribute %{attr}"
87
+ ensure_valid_name_format_of:
88
+ failure_message_for_should: "%{model} should ensure valid name format of attribute %{attr}"
89
+ failure_message_for_should_not: "%{model} should not ensure valid name format of attribute %{attr}"
90
+ ensure_valid_password_format_of:
91
+ failure_message_for_should: "%{model} should ensure valid password format of attribute %{attr}"
92
+ failure_message_for_should_not: "%{model} should not ensure valid password format of attribute %{attr}"
93
+ ensure_valid_phone_format_of:
94
+ failure_message_for_should: "%{model} should ensure valid phone format of attribute %{attr}"
95
+ failure_message_for_should_not: "%{model} should not ensure valid phone format of attribute %{attr}"
96
+ ensure_valid_sedol_format_of:
97
+ failure_message_for_should: "%{model} should ensure valid SEDOL format of attribute %{attr}"
98
+ failure_message_for_should_not: "%{model} should not ensure valid SEDOL format of attribute %{attr}"
99
+ ensure_valid_slug_format_of:
100
+ failure_message_for_should: "%{model} should ensure valid slug format of attribute %{attr}"
101
+ failure_message_for_should_not: "%{model} should not ensure valid slug format of attribute %{attr}"
102
+ ensure_valid_ssn_format_of:
103
+ failure_message_for_should: "%{model} should ensure valid SSN format of attribute %{attr}"
104
+ failure_message_for_should_not: "%{model} should not ensure valid SSN format of attribute %{attr}"
105
+ ensure_valid_url_format_of:
106
+ failure_message_for_should: "%{model} should ensure valid URL format of attribute %{attr}"
107
+ failure_message_for_should_not: "%{model} should not ensure valid URL format of attribute %{attr}"
108
+ ensure_valid_username_format_of:
109
+ failure_message_for_should: "%{model} should ensure valid username format of attribute %{attr}"
110
+ failure_message_for_should_not: "%{model} should not ensure valid username format of attribute %{attr}"
111
+ ensure_valid_uuid_format_of:
112
+ failure_message_for_should: "%{model} should ensure valid UUID format of attribute %{attr}"
113
+ failure_message_for_should_not: "%{model} should not ensure valid UUID format of attribute %{attr}"
@@ -0,0 +1,93 @@
1
+ require 'active_model'
2
+ require 'active_support'
3
+ require 'yukonisuru/version'
4
+
5
+ require 'yukonisuru/validators/alpha_validator'
6
+ require 'yukonisuru/validators/alpha_numeric_validator'
7
+ require 'yukonisuru/validators/base64_validator'
8
+ require 'yukonisuru/validators/boolean_validator'
9
+ require 'yukonisuru/validators/credit_card_validator'
10
+ require 'yukonisuru/validators/currency_validator'
11
+ require 'yukonisuru/validators/cusip_validator'
12
+ require 'yukonisuru/validators/email_validator'
13
+ require 'yukonisuru/validators/equality_validator'
14
+ require 'yukonisuru/validators/gtin_validator'
15
+ require 'yukonisuru/validators/hex_validator'
16
+ require 'yukonisuru/validators/imei_validator'
17
+ require 'yukonisuru/validators/ip_validator'
18
+ require 'yukonisuru/validators/isbn_validator'
19
+ require 'yukonisuru/validators/isin_validator'
20
+ require 'yukonisuru/validators/latitude_validator'
21
+ require 'yukonisuru/validators/longitude_validator'
22
+ require 'yukonisuru/validators/mac_address_validator'
23
+ require 'yukonisuru/validators/name_validator'
24
+ require 'yukonisuru/validators/password_validator'
25
+ require 'yukonisuru/validators/phone_validator'
26
+ require 'yukonisuru/validators/sedol_validator'
27
+ require 'yukonisuru/validators/slug_validator'
28
+ require 'yukonisuru/validators/ssn_validator'
29
+ require 'yukonisuru/validators/url_validator'
30
+ require 'yukonisuru/validators/username_validator'
31
+ require 'yukonisuru/validators/uuid_validator'
32
+
33
+ if defined?(RSpec)
34
+ require 'rspec/matchers'
35
+ require 'yukonisuru/matchers/ensure_valid_alpha_format_of'
36
+ require 'yukonisuru/matchers/ensure_valid_alpha_numeric_format_of'
37
+ require 'yukonisuru/matchers/ensure_valid_base64_format_of'
38
+ require 'yukonisuru/matchers/ensure_valid_boolean_format_of'
39
+ require 'yukonisuru/matchers/ensure_valid_credit_card_format_of'
40
+ require 'yukonisuru/matchers/ensure_valid_currency_format_of'
41
+ require 'yukonisuru/matchers/ensure_valid_cusip_format_of'
42
+ require 'yukonisuru/matchers/ensure_valid_email_format_of'
43
+ require 'yukonisuru/matchers/ensure_valid_equality_matcher_of'
44
+ require 'yukonisuru/matchers/ensure_valid_gtin_format_of'
45
+ require 'yukonisuru/matchers/ensure_valid_hex_format_of'
46
+ require 'yukonisuru/matchers/ensure_valid_imei_format_of'
47
+ require 'yukonisuru/matchers/ensure_valid_ip_format_of'
48
+ require 'yukonisuru/matchers/ensure_valid_isbn_format_of'
49
+ require 'yukonisuru/matchers/ensure_valid_isin_format_of'
50
+ require 'yukonisuru/matchers/ensure_valid_latitude_format_of'
51
+ require 'yukonisuru/matchers/ensure_valid_longitude_format_of'
52
+ require 'yukonisuru/matchers/ensure_valid_mac_address_format_of'
53
+ require 'yukonisuru/matchers/ensure_valid_name_format_of'
54
+ require 'yukonisuru/matchers/ensure_valid_password_format_of'
55
+ require 'yukonisuru/matchers/ensure_valid_phone_format_of'
56
+ require 'yukonisuru/matchers/ensure_valid_sedol_format_of'
57
+ require 'yukonisuru/matchers/ensure_valid_slug_format_of'
58
+ require 'yukonisuru/matchers/ensure_valid_ssn_format_of'
59
+ require 'yukonisuru/matchers/ensure_valid_url_format_of'
60
+ require 'yukonisuru/matchers/ensure_valid_username_format_of'
61
+ require 'yukonisuru/matchers/ensure_valid_uuid_format_of'
62
+ end
63
+
64
+ if defined?(Rails)
65
+ require 'rails'
66
+
67
+ module Yukonisuru
68
+ class Railtie < ::Rails::Railtie
69
+ initializer 'yukonisuru' do |app|
70
+ Yukonisuru::Railtie.instance_eval do
71
+ locales = locales_from(app.config.i18n.available_locales)
72
+
73
+ locales.each do |locale|
74
+ if File.file?(path(locale))
75
+ I18n.load_path << path(locale)
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ protected
82
+
83
+ def self.path(locale)
84
+ File.expand_path("../../config/locales/#{locale}.yml", __FILE__)
85
+ end
86
+
87
+ def self.locales_from(args)
88
+ array = Array(args || [])
89
+ array.blank? ? '*' : array
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_alpha_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "$1234.56")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('yukonisuru.errors.messages.alpha'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'yukonisuru.matchers.ensure_valid_alpha_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'yukonisuru.matchers.ensure_valid_alpha_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_alpha_numeric_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "$1234.56")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('yukonisuru.errors.messages.alpha_numeric'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'yukonisuru.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'yukonisuru.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_base64_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "1a.b2==")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('yukonisuru.errors.messages.base64'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'yukonisuru.matchers.ensure_valid_base64_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'yukonisuru.matchers.ensure_valid_base64_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_boolean_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", nil)
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('yukonisuru.errors.messages.boolean'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'yukonisuru.matchers.ensure_valid_boolean_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'yukonisuru.matchers.ensure_valid_boolean_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_credit_card_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "9999")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('yukonisuru.errors.messages.credit_card'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'yukonisuru.matchers.ensure_valid_credit_card_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'yukonisuru.matchers.ensure_valid_credit_card_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_currency_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "$1234.56")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('yukonisuru.errors.messages.currency'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'yukonisuru.matchers.ensure_valid_currency_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'yukonisuru.matchers.ensure_valid_currency_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_cusip_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "1234567890")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('yukonisuru.errors.messages.cusip'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'yukonisuru.matchers.ensure_valid_cusip_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'yukonisuru.matchers.ensure_valid_cusip_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ RSpec::Matchers.define :ensure_valid_email_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "invalid@email_address")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('yukonisuru.errors.messages.email'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t(
13
+ 'yukonisuru.matchers.ensure_valid_email_format_of.failure_message_for_should',
14
+ attr: attribute.inspect,
15
+ model: model.class.name
16
+ )
17
+ end
18
+
19
+ failure_message_when_negated do |model|
20
+ I18n.t(
21
+ 'yukonisuru.matchers.ensure_valid_email_format_of.failure_message_for_should_not',
22
+ attr: attribute.inspect,
23
+ model: model.class.name
24
+ )
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ RSpec::Matchers.define :ensure_equality_of do |attribute|
2
+ chain :to do |to|
3
+ @to = to
4
+ end
5
+
6
+ chain :operator do |operator|
7
+ @operator = operator
8
+ end
9
+
10
+ match do |model|
11
+ raise Exception if @to.nil? || @operator.nil?
12
+
13
+ value = model.send(attribute)
14
+ model.send("#{@to}=", value)
15
+ model.send("#{@operator}=", value)
16
+ model.valid?
17
+
18
+ if model.errors.has_key?(attribute)
19
+ model.errors[attribute].include?(I18n.t('yukonisuru.errors.messages.equality', attr: @to, operator: @operator))
20
+ end
21
+ end
22
+
23
+ failure_message do |model|
24
+ I18n.t(
25
+ 'yukonisuru.matchers.ensure_valid_equality_format_of.failure_message_for_should',
26
+ attr: attribute.inspect,
27
+ model: model.class.name,
28
+ operator: "operator"
29
+ )
30
+ end
31
+
32
+ failure_message_when_negated do |model|
33
+ I18n.t(
34
+ 'yukonisuru.matchers.ensure_valid_equality_format_of.failure_message_for_should_not',
35
+ attr: attribute.inspect,
36
+ model: model.class.name,
37
+ operator: "operator"
38
+ )
39
+ end
40
+ end