test_track_rails_client 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +11 -8
  3. data/lib/test_track_rails_client/version.rb +1 -1
  4. data/vendor/gems/fakeable_her/fakeable_her.gemspec +22 -0
  5. data/vendor/gems/fakeable_her/lib/fakeable_her/model.rb +148 -0
  6. data/vendor/gems/fakeable_her/lib/fakeable_her/version.rb +3 -0
  7. data/vendor/gems/fakeable_her/lib/fakeable_her.rb +5 -0
  8. data/vendor/gems/her/CONTRIBUTING.md +26 -0
  9. data/vendor/gems/her/Gemfile +10 -0
  10. data/vendor/gems/her/LICENSE +7 -0
  11. data/vendor/gems/her/README.md +1023 -0
  12. data/vendor/gems/her/Rakefile +11 -0
  13. data/vendor/gems/her/UPGRADE.md +101 -0
  14. data/vendor/gems/her/gemfiles/Gemfile.activemodel-3.2.x +7 -0
  15. data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.0 +7 -0
  16. data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.1 +7 -0
  17. data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.2 +7 -0
  18. data/vendor/gems/her/her.gemspec +31 -0
  19. data/vendor/gems/her/lib/her/api.rb +119 -0
  20. data/vendor/gems/her/lib/her/collection.rb +12 -0
  21. data/vendor/gems/her/lib/her/error_collection.rb +15 -0
  22. data/vendor/gems/her/lib/her/errors.rb +40 -0
  23. data/vendor/gems/her/lib/her/json_api/model.rb +46 -0
  24. data/vendor/gems/her/lib/her/middleware/accept_json.rb +17 -0
  25. data/vendor/gems/her/lib/her/middleware/first_level_parse_json.rb +36 -0
  26. data/vendor/gems/her/lib/her/middleware/json_api_parser.rb +36 -0
  27. data/vendor/gems/her/lib/her/middleware/parse_json.rb +21 -0
  28. data/vendor/gems/her/lib/her/middleware/second_level_parse_json.rb +36 -0
  29. data/vendor/gems/her/lib/her/middleware.rb +12 -0
  30. data/vendor/gems/her/lib/her/model/active_model_overrides.rb +13 -0
  31. data/vendor/gems/her/lib/her/model/associations/association.rb +106 -0
  32. data/vendor/gems/her/lib/her/model/associations/association_proxy.rb +46 -0
  33. data/vendor/gems/her/lib/her/model/associations/belongs_to_association.rb +96 -0
  34. data/vendor/gems/her/lib/her/model/associations/has_many_association.rb +100 -0
  35. data/vendor/gems/her/lib/her/model/associations/has_one_association.rb +79 -0
  36. data/vendor/gems/her/lib/her/model/associations.rb +141 -0
  37. data/vendor/gems/her/lib/her/model/attributes.rb +304 -0
  38. data/vendor/gems/her/lib/her/model/base.rb +33 -0
  39. data/vendor/gems/her/lib/her/model/deprecated_methods.rb +61 -0
  40. data/vendor/gems/her/lib/her/model/http.rb +117 -0
  41. data/vendor/gems/her/lib/her/model/introspection.rb +65 -0
  42. data/vendor/gems/her/lib/her/model/nested_attributes.rb +45 -0
  43. data/vendor/gems/her/lib/her/model/orm.rb +219 -0
  44. data/vendor/gems/her/lib/her/model/parse.rb +215 -0
  45. data/vendor/gems/her/lib/her/model/paths.rb +126 -0
  46. data/vendor/gems/her/lib/her/model/relation.rb +251 -0
  47. data/vendor/gems/her/lib/her/model.rb +81 -0
  48. data/vendor/gems/her/lib/her/version.rb +3 -0
  49. data/vendor/gems/her/lib/her.rb +20 -0
  50. data/vendor/gems/her/spec/api_spec.rb +114 -0
  51. data/vendor/gems/her/spec/collection_spec.rb +26 -0
  52. data/vendor/gems/her/spec/error_collection_spec.rb +33 -0
  53. data/vendor/gems/her/spec/json_api/model_spec.rb +168 -0
  54. data/vendor/gems/her/spec/middleware/accept_json_spec.rb +10 -0
  55. data/vendor/gems/her/spec/middleware/first_level_parse_json_spec.rb +62 -0
  56. data/vendor/gems/her/spec/middleware/json_api_parser_spec.rb +32 -0
  57. data/vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb +35 -0
  58. data/vendor/gems/her/spec/model/associations/association_proxy_spec.rb +31 -0
  59. data/vendor/gems/her/spec/model/associations_spec.rb +504 -0
  60. data/vendor/gems/her/spec/model/attributes_spec.rb +404 -0
  61. data/vendor/gems/her/spec/model/callbacks_spec.rb +145 -0
  62. data/vendor/gems/her/spec/model/dirty_spec.rb +110 -0
  63. data/vendor/gems/her/spec/model/http_spec.rb +165 -0
  64. data/vendor/gems/her/spec/model/introspection_spec.rb +76 -0
  65. data/vendor/gems/her/spec/model/nested_attributes_spec.rb +134 -0
  66. data/vendor/gems/her/spec/model/orm_spec.rb +791 -0
  67. data/vendor/gems/her/spec/model/parse_spec.rb +372 -0
  68. data/vendor/gems/her/spec/model/paths_spec.rb +347 -0
  69. data/vendor/gems/her/spec/model/relation_spec.rb +226 -0
  70. data/vendor/gems/her/spec/model/validations_spec.rb +42 -0
  71. data/vendor/gems/her/spec/model_spec.rb +31 -0
  72. data/vendor/gems/her/spec/spec_helper.rb +27 -0
  73. data/vendor/gems/her/spec/support/extensions/array.rb +5 -0
  74. data/vendor/gems/her/spec/support/extensions/hash.rb +5 -0
  75. data/vendor/gems/her/spec/support/macros/her_macros.rb +17 -0
  76. data/vendor/gems/her/spec/support/macros/model_macros.rb +36 -0
  77. data/vendor/gems/her/spec/support/macros/request_macros.rb +27 -0
  78. data/vendor/gems/publicsuffix-ruby/CHANGELOG.md +236 -0
  79. data/vendor/gems/publicsuffix-ruby/Gemfile +3 -0
  80. data/vendor/gems/publicsuffix-ruby/LICENSE.txt +22 -0
  81. data/vendor/gems/publicsuffix-ruby/README.md +151 -0
  82. data/vendor/gems/publicsuffix-ruby/Rakefile +109 -0
  83. data/vendor/gems/publicsuffix-ruby/lib/definitions.txt +11467 -0
  84. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/domain.rb +387 -0
  85. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/errors.rb +53 -0
  86. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/list.rb +302 -0
  87. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/rule.rb +373 -0
  88. data/vendor/gems/publicsuffix-ruby/lib/public_suffix/version.rb +23 -0
  89. data/vendor/gems/publicsuffix-ruby/lib/public_suffix.rb +131 -0
  90. data/vendor/gems/publicsuffix-ruby/public_suffix.gemspec +39 -0
  91. data/vendor/gems/publicsuffix-ruby/test/acceptance_test.rb +42 -0
  92. data/vendor/gems/publicsuffix-ruby/test/test_helper.rb +6 -0
  93. data/vendor/gems/publicsuffix-ruby/test/unit/domain_test.rb +170 -0
  94. data/vendor/gems/publicsuffix-ruby/test/unit/errors_test.rb +23 -0
  95. data/vendor/gems/publicsuffix-ruby/test/unit/list_test.rb +179 -0
  96. data/vendor/gems/publicsuffix-ruby/test/unit/public_suffix_test.rb +115 -0
  97. data/vendor/gems/publicsuffix-ruby/test/unit/rule_test.rb +307 -0
  98. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/capybara_configuration.rb +98 -0
  99. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/matchers.rb +151 -0
  100. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rspec_configuration.rb +34 -0
  101. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/html_safe.rb +15 -0
  102. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/raw.rb +15 -0
  103. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/safe_concat.rb +15 -0
  104. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop.rb +3 -0
  105. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/shared_examples/betterment_application_examples.rb +47 -0
  106. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/shared_examples.rb +1 -0
  107. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/site_prism_configuration.rb +42 -0
  108. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/site_prism_dropdown.rb +17 -0
  109. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/version.rb +3 -0
  110. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/webmock_configuration.rb +8 -0
  111. data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers.rb +2 -0
  112. data/vendor/gems/ruby_spec_helpers/ruby_spec_helpers.gemspec +25 -0
  113. metadata +110 -1
@@ -0,0 +1,115 @@
1
+ require 'test_helper'
2
+
3
+ class PublicSuffixTest < Test::Unit::TestCase
4
+
5
+ def test_self_parse_a_domain_with_tld_and_sld
6
+ domain = PublicSuffix.parse("example.com")
7
+ assert_instance_of PublicSuffix::Domain, domain
8
+ assert_equal "com", domain.tld
9
+ assert_equal "example", domain.sld
10
+ assert_equal nil, domain.trd
11
+
12
+ domain = PublicSuffix.parse("example.co.uk")
13
+ assert_instance_of PublicSuffix::Domain, domain
14
+ assert_equal "co.uk", domain.tld
15
+ assert_equal "example", domain.sld
16
+ assert_equal nil, domain.trd
17
+ end
18
+
19
+ def test_self_parse_a_domain_with_tld_and_sld_and_trd
20
+ domain = PublicSuffix.parse("alpha.example.com")
21
+ assert_instance_of PublicSuffix::Domain, domain
22
+ assert_equal "com", domain.tld
23
+ assert_equal "example", domain.sld
24
+ assert_equal "alpha", domain.trd
25
+
26
+ domain = PublicSuffix.parse("alpha.example.co.uk")
27
+ assert_instance_of PublicSuffix::Domain, domain
28
+ assert_equal "co.uk", domain.tld
29
+ assert_equal "example", domain.sld
30
+ assert_equal "alpha", domain.trd
31
+ end
32
+
33
+ def test_self_parse_a_domain_with_tld_and_sld_and_4rd
34
+ domain = PublicSuffix.parse("one.two.example.com")
35
+ assert_instance_of PublicSuffix::Domain, domain
36
+ assert_equal "com", domain.tld
37
+ assert_equal "example", domain.sld
38
+ assert_equal "one.two", domain.trd
39
+
40
+ domain = PublicSuffix.parse("one.two.example.co.uk")
41
+ assert_instance_of PublicSuffix::Domain, domain
42
+ assert_equal "co.uk", domain.tld
43
+ assert_equal "example", domain.sld
44
+ assert_equal "one.two", domain.trd
45
+ end
46
+
47
+ def test_self_parse_a_fully_qualified_domain_name
48
+ domain = PublicSuffix.parse("www.example.com.")
49
+ assert_instance_of PublicSuffix::Domain, domain
50
+ assert_equal "com", domain.tld
51
+ assert_equal "example", domain.sld
52
+ assert_equal "www", domain.trd
53
+ end
54
+
55
+ def test_private_domains_are_enabled_by_default
56
+ domain = PublicSuffix.parse("www.example.blogspot.com")
57
+ assert_equal "blogspot.com", domain.tld
58
+ end
59
+
60
+ def test_disable_support_for_private_domains
61
+ begin
62
+ PublicSuffix::List.private_domains = false
63
+ domain = PublicSuffix.parse("www.example.blogspot.com")
64
+ assert_equal "com", domain.tld
65
+ ensure
66
+ PublicSuffix::List.private_domains = true
67
+ end
68
+ end
69
+
70
+ def test_self_parse_a_domain_with_custom_list
71
+ list = PublicSuffix::List.new
72
+ list << PublicSuffix::Rule.factory("test")
73
+
74
+ domain = PublicSuffix.parse("www.example.test", list)
75
+ assert_equal "test", domain.tld
76
+ assert_equal "example", domain.sld
77
+ assert_equal "www", domain.trd
78
+ end
79
+
80
+ def test_self_parse_raises_with_invalid_domain
81
+ error = assert_raise(PublicSuffix::DomainInvalid) { PublicSuffix.parse("example.qqq") }
82
+ assert_match %r{example\.qqq}, error.message
83
+ end
84
+
85
+ def test_self_parse_raises_with_unallowed_domain
86
+ error = assert_raise(PublicSuffix::DomainNotAllowed) { PublicSuffix.parse("example.ke") }
87
+ assert_match %r{example\.ke}, error.message
88
+ end
89
+
90
+ def test_self_raises_with_uri
91
+ error = assert_raise(PublicSuffix::DomainInvalid) { PublicSuffix.parse("http://google.com") }
92
+ assert_match %r{http://google\.com}, error.message
93
+ end
94
+
95
+
96
+ def test_self_valid
97
+ assert PublicSuffix.valid?("google.com")
98
+ assert PublicSuffix.valid?("www.google.com")
99
+ assert PublicSuffix.valid?("google.co.uk")
100
+ assert PublicSuffix.valid?("www.google.co.uk")
101
+ end
102
+
103
+ # Returns false when domain has an invalid TLD
104
+ def test_self_valid_with_invalid_tld
105
+ assert !PublicSuffix.valid?("google.qqq")
106
+ assert !PublicSuffix.valid?("www.google.qqq")
107
+ end
108
+
109
+ def test_self_valid_with_fully_qualified_domain_name
110
+ assert PublicSuffix.valid?("google.com.")
111
+ assert PublicSuffix.valid?("google.co.uk.")
112
+ assert !PublicSuffix.valid?("google.qqq.")
113
+ end
114
+
115
+ end
@@ -0,0 +1,307 @@
1
+ require 'test_helper'
2
+
3
+ class PublicSuffix::RuleTest < Test::Unit::TestCase
4
+
5
+ def test_factory_should_return_rule_normal
6
+ rule = PublicSuffix::Rule.factory("com")
7
+ assert_instance_of PublicSuffix::Rule::Normal, rule
8
+
9
+ rule = PublicSuffix::Rule.factory("verona.it")
10
+ assert_instance_of PublicSuffix::Rule::Normal, rule
11
+ end
12
+
13
+ def test_factory_should_return_rule_exception
14
+ rule = PublicSuffix::Rule.factory("!british-library.uk")
15
+ assert_instance_of PublicSuffix::Rule::Exception, rule
16
+ end
17
+
18
+ def test_factory_should_return_rule_wildcard
19
+ rule = PublicSuffix::Rule.factory("*.do")
20
+ assert_instance_of PublicSuffix::Rule::Wildcard, rule
21
+
22
+ rule = PublicSuffix::Rule.factory("*.sch.uk")
23
+ assert_instance_of PublicSuffix::Rule::Wildcard, rule
24
+ end
25
+
26
+ end
27
+
28
+
29
+ class PublicSuffix::RuleBaseTest < Test::Unit::TestCase
30
+
31
+ class ::PublicSuffix::Rule::Test < ::PublicSuffix::Rule::Base
32
+ end
33
+
34
+ def setup
35
+ @klass = PublicSuffix::Rule::Base
36
+ end
37
+
38
+
39
+ def test_initialize
40
+ rule = @klass.new("verona.it")
41
+ assert_instance_of @klass, rule
42
+
43
+ assert_equal :base, rule.type
44
+ assert_equal "verona.it", rule.name
45
+ assert_equal "verona.it", rule.value
46
+ assert_equal %w(verona it).reverse, rule.labels
47
+ end
48
+
49
+ def test_equality_with_self
50
+ rule = PublicSuffix::Rule::Base.new("foo")
51
+ assert_equal rule, rule
52
+ end
53
+
54
+ def test_equality_with_internals
55
+ assert_equal @klass.new("foo"), @klass.new("foo")
56
+ assert_not_equal @klass.new("foo"), @klass.new("bar")
57
+ assert_not_equal @klass.new("foo"), PublicSuffix::Rule::Test.new("bar")
58
+ assert_not_equal @klass.new("foo"), Class.new { def name; foo; end }.new
59
+ end
60
+
61
+
62
+ def test_match
63
+ assert @klass.new("uk").match?("example.uk")
64
+ assert !@klass.new("gk").match?("example.uk")
65
+ assert !@klass.new("example").match?("example.uk")
66
+
67
+ assert @klass.new("uk").match?("example.co.uk")
68
+ assert !@klass.new("gk").match?("example.co.uk")
69
+ assert !@klass.new("co").match?("example.co.uk")
70
+
71
+ assert @klass.new("co.uk").match?("example.co.uk")
72
+ assert !@klass.new("uk.co").match?("example.co.uk")
73
+ assert !@klass.new("go.uk").match?("example.co.uk")
74
+ end
75
+
76
+ def test_length
77
+ assert_raise(NotImplementedError) { @klass.new("com").length }
78
+ end
79
+
80
+ def test_parts
81
+ assert_raise(NotImplementedError) { @klass.new("com").parts }
82
+ end
83
+
84
+ def test_decompose
85
+ assert_raise(NotImplementedError) { @klass.new("com").decompose("google.com") }
86
+ end
87
+
88
+ end
89
+
90
+
91
+ class PublicSuffix::RuleNormalTest < Test::Unit::TestCase
92
+
93
+ def setup
94
+ @klass = PublicSuffix::Rule::Normal
95
+ end
96
+
97
+
98
+ def test_initialize
99
+ rule = @klass.new("verona.it")
100
+ assert_instance_of @klass, rule
101
+ assert_equal :normal, rule.type
102
+ assert_equal "verona.it", rule.name
103
+ assert_equal "verona.it", rule.value
104
+ assert_equal %w(verona it).reverse, rule.labels
105
+ end
106
+
107
+
108
+ def test_match
109
+ assert @klass.new("uk").match?("example.uk")
110
+ assert !@klass.new("gk").match?("example.uk")
111
+ assert !@klass.new("example").match?("example.uk")
112
+
113
+ assert @klass.new("uk").match?("example.co.uk")
114
+ assert !@klass.new("gk").match?("example.co.uk")
115
+ assert !@klass.new("co").match?("example.co.uk")
116
+
117
+ assert @klass.new("co.uk").match?("example.co.uk")
118
+ assert !@klass.new("uk.co").match?("example.co.uk")
119
+ assert !@klass.new("go.uk").match?("example.co.uk")
120
+ end
121
+
122
+ def test_match_with_fully_qualified_domain_name
123
+ assert @klass.new("com").match?("com.")
124
+ assert @klass.new("com").match?("example.com.")
125
+ assert @klass.new("com").match?("www.example.com.")
126
+ end
127
+
128
+ def test_allow
129
+ assert !@klass.new("com").allow?("com")
130
+ assert @klass.new("com").allow?("example.com")
131
+ assert @klass.new("com").allow?("www.example.com")
132
+ end
133
+
134
+ def test_allow_with_fully_qualified_domain_name
135
+ assert !@klass.new("com").allow?("com.")
136
+ assert @klass.new("com").allow?("example.com.")
137
+ assert @klass.new("com").allow?("www.example.com.")
138
+ end
139
+
140
+
141
+ def test_length
142
+ assert_equal 1, @klass.new("com").length
143
+ assert_equal 2, @klass.new("co.com").length
144
+ assert_equal 3, @klass.new("mx.co.com").length
145
+ end
146
+
147
+ def test_parts
148
+ assert_equal %w(com), @klass.new("com").parts
149
+ assert_equal %w(co com), @klass.new("co.com").parts
150
+ assert_equal %w(mx co com), @klass.new("mx.co.com").parts
151
+ end
152
+
153
+ def test_decompose
154
+ assert_equal [nil, nil], @klass.new("com").decompose("com")
155
+ assert_equal %w( example com ), @klass.new("com").decompose("example.com")
156
+ assert_equal %w( foo.example com ), @klass.new("com").decompose("foo.example.com")
157
+ end
158
+
159
+ def test_decompose_with_fully_qualified_domain_name
160
+ assert_equal [nil, nil], @klass.new("com").decompose("com.")
161
+ assert_equal %w( example com ), @klass.new("com").decompose("example.com.")
162
+ assert_equal %w( foo.example com ), @klass.new("com").decompose("foo.example.com.")
163
+ end
164
+
165
+ end
166
+
167
+
168
+ class PublicSuffix::RuleExceptionTest < Test::Unit::TestCase
169
+
170
+ def setup
171
+ @klass = PublicSuffix::Rule::Exception
172
+ end
173
+
174
+
175
+ def test_initialize
176
+ rule = @klass.new("!british-library.uk")
177
+ assert_instance_of @klass, rule
178
+ assert_equal :exception, rule.type
179
+ assert_equal "!british-library.uk", rule.name
180
+ assert_equal "british-library.uk", rule.value
181
+ assert_equal %w(british-library uk).reverse, rule.labels
182
+ end
183
+
184
+
185
+ def test_match
186
+ assert @klass.new("!uk").match?("example.co.uk")
187
+ assert !@klass.new("!gk").match?("example.co.uk")
188
+ assert @klass.new("!co.uk").match?("example.co.uk")
189
+ assert !@klass.new("!go.uk").match?("example.co.uk")
190
+ assert @klass.new("!british-library.uk").match?("british-library.uk")
191
+ assert !@klass.new("!british-library.uk").match?("example.co.uk")
192
+ end
193
+
194
+ def test_match_with_fully_qualified_domain_name
195
+ assert @klass.new("!uk").match?("uk.")
196
+ assert @klass.new("!uk").match?("co.uk.")
197
+ assert @klass.new("!uk").match?("example.co.uk.")
198
+ assert @klass.new("!uk").match?("www.example.co.uk.")
199
+ end
200
+
201
+ def test_allow
202
+ assert !@klass.new("!british-library.uk").allow?("uk")
203
+ assert @klass.new("!british-library.uk").allow?("british-library.uk")
204
+ assert @klass.new("!british-library.uk").allow?("www.british-library.uk")
205
+ end
206
+
207
+ def test_allow_with_fully_qualified_domain_name
208
+ assert !@klass.new("!british-library.uk").allow?("uk.")
209
+ assert @klass.new("!british-library.uk").allow?("british-library.uk.")
210
+ assert @klass.new("!british-library.uk").allow?("www.british-library.uk.")
211
+ end
212
+
213
+
214
+ def test_length
215
+ assert_equal 1, @klass.new("!british-library.uk").length
216
+ assert_equal 2, @klass.new("!foo.british-library.uk").length
217
+ end
218
+
219
+ def test_parts
220
+ assert_equal %w( uk ), @klass.new("!british-library.uk").parts
221
+ assert_equal %w( tokyo jp ), @klass.new("!metro.tokyo.jp").parts
222
+ end
223
+
224
+ def test_decompose
225
+ assert_equal [nil, nil], @klass.new("!british-library.uk").decompose("uk")
226
+ assert_equal %w( british-library uk ), @klass.new("!british-library.uk").decompose("british-library.uk")
227
+ assert_equal %w( foo.british-library uk ), @klass.new("!british-library.uk").decompose("foo.british-library.uk")
228
+ end
229
+
230
+ def test_decompose_with_fully_qualified_domain_name
231
+ assert_equal [nil, nil], @klass.new("!british-library.uk").decompose("uk.")
232
+ assert_equal %w( british-library uk ), @klass.new("!british-library.uk").decompose("british-library.uk.")
233
+ assert_equal %w( foo.british-library uk ), @klass.new("!british-library.uk").decompose("foo.british-library.uk.")
234
+ end
235
+
236
+ end
237
+
238
+
239
+ class PublicSuffix::RuleWildcardTest < Test::Unit::TestCase
240
+
241
+ def setup
242
+ @klass = PublicSuffix::Rule::Wildcard
243
+ end
244
+
245
+
246
+ def test_initialize
247
+ rule = @klass.new("*.aichi.jp")
248
+ assert_instance_of @klass, rule
249
+ assert_equal :wildcard, rule.type
250
+ assert_equal "*.aichi.jp", rule.name
251
+ assert_equal "aichi.jp", rule.value
252
+ assert_equal %w(aichi jp).reverse, rule.labels
253
+ end
254
+
255
+
256
+ def test_match
257
+ assert @klass.new("*.uk").match?("example.uk")
258
+ assert @klass.new("*.uk").match?("example.co.uk")
259
+ assert @klass.new("*.co.uk").match?("example.co.uk")
260
+ assert !@klass.new("*.go.uk").match?("example.co.uk")
261
+ end
262
+
263
+ def test_match_with_fully_qualified_domain_name
264
+ assert @klass.new("*.uk").match?("uk.")
265
+ assert @klass.new("*.uk").match?("co.uk.")
266
+ assert @klass.new("*.uk").match?("example.co.uk.")
267
+ assert @klass.new("*.uk").match?("www.example.co.uk.")
268
+ end
269
+
270
+ def test_allow
271
+ assert !@klass.new("*.uk").allow?("uk")
272
+ assert !@klass.new("*.uk").allow?("co.uk")
273
+ assert @klass.new("*.uk").allow?("example.co.uk")
274
+ assert @klass.new("*.uk").allow?("www.example.co.uk")
275
+ end
276
+
277
+ def test_allow_with_fully_qualified_domain_name
278
+ assert !@klass.new("*.uk").allow?("uk.")
279
+ assert !@klass.new("*.uk").allow?("co.uk.")
280
+ assert @klass.new("*.uk").allow?("example.co.uk.")
281
+ assert @klass.new("*.uk").allow?("www.example.co.uk.")
282
+ end
283
+
284
+
285
+ def test_length
286
+ assert_equal 2, @klass.new("*.uk").length
287
+ assert_equal 3, @klass.new("*.co.uk").length
288
+ end
289
+
290
+ def test_parts
291
+ assert_equal %w( uk ), @klass.new("*.uk").parts
292
+ assert_equal %w( co uk ), @klass.new("*.co.uk").parts
293
+ end
294
+
295
+ def test_decompose
296
+ assert_equal [nil, nil], @klass.new("*.do").decompose("nic.do")
297
+ assert_equal %w( google co.uk ), @klass.new("*.uk").decompose("google.co.uk")
298
+ assert_equal %w( foo.google co.uk ), @klass.new("*.uk").decompose("foo.google.co.uk")
299
+ end
300
+
301
+ def test_decompose_with_fully_qualified_domain_name
302
+ assert_equal [nil, nil], @klass.new("*.do").decompose("nic.do.")
303
+ assert_equal %w( google co.uk ), @klass.new("*.uk").decompose("google.co.uk.")
304
+ assert_equal %w( foo.google co.uk ), @klass.new("*.uk").decompose("foo.google.co.uk.")
305
+ end
306
+
307
+ end
@@ -0,0 +1,98 @@
1
+ require 'capybara/rails'
2
+ require 'capybara/rspec'
3
+ require 'selenium-webdriver'
4
+ require 'fileutils'
5
+
6
+ ENV["SCREENSHOT_DIR"] ||= Time.now.to_i.to_s
7
+ capybara_wait_time = (ENV['CAPYBARA_WAIT_TIME'] || 10).to_i
8
+ driver = (ENV["DRIVER"] || "webkit").to_sym
9
+ webkit_debug = (!ENV["WEBKIT_DEBUG"].nil? && ENV["WEBKIT_DEBUG"] == "true") ? true : false
10
+
11
+ case driver
12
+ when :webkit
13
+ Capybara.register_driver :webkit do |app|
14
+ browser = Capybara::Webkit::Browser.new(Capybara::Webkit::Connection.new).tap do |browser|
15
+ browser.ignore_ssl_errors
16
+ end
17
+ driver = Capybara::Webkit::Driver.new(app, browser: browser)
18
+ driver.enable_logging if webkit_debug
19
+ driver
20
+ end
21
+ when :poltergeist
22
+ require 'capybara/poltergeist'
23
+ Capybara.register_driver :poltergeist do |app|
24
+ driver = Capybara::Poltergeist::Driver.new(app, js_errors: false, phantomjs_logger: Logger.new('/dev/null'))
25
+ driver
26
+ end
27
+ else
28
+ Capybara.register_driver driver do |app|
29
+ Capybara::Selenium::Driver.new(app, browser: driver)
30
+ end
31
+ end
32
+
33
+ Capybara.configure do |config|
34
+ config.match = :one
35
+ config.exact_options = true
36
+ config.ignore_hidden_elements = true
37
+ config.visible_text_only = true
38
+ config.default_wait_time = capybara_wait_time
39
+ config.default_driver = driver
40
+ config.javascript_driver = driver
41
+ end
42
+
43
+ module CapybaraScreenshotHelpers
44
+ def screenshot(filename)
45
+ options = {}
46
+ case Capybara.current_driver
47
+ when :webkit
48
+ options[:width] = page.driver.evaluate_script("document.documentElement.clientWidth")
49
+ options[:height] = page.driver.evaluate_script("document.documentElement.clientHeight")
50
+ when :poltergeist
51
+ options[:full] = true
52
+ end
53
+ page.save_screenshot "#{filename}", options
54
+ end
55
+
56
+ private
57
+
58
+ def screenshot_name(example)
59
+ "#{example.metadata[:full_description]}.png".gsub(/\ /, "_")
60
+ end
61
+
62
+ def screenshot_on_error(example)
63
+ if !example.exception.nil?
64
+ dirname = "spec/error_screenshots/#{ENV["SCREENSHOT_DIR"]}"
65
+ FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
66
+ screenshot "#{dirname}/#{screenshot_name(example)}"
67
+ end
68
+ end
69
+
70
+ def print_console_messages
71
+ if page.driver.respond_to?(:errors_messages)
72
+ p page.driver.error_messages unless page.driver.error_messages.empty?
73
+ # uncomment for ALL console messages, not just console.error
74
+ # p page.driver.console_messages unless page.driver.console_messages.empty?
75
+ end
76
+ end
77
+ end
78
+
79
+ RSpec.configure do |config|
80
+ config.include CapybaraScreenshotHelpers, type: :feature
81
+
82
+ config.after(:each, type: :feature) do |example|
83
+ if example.exception && page.driver.respond_to?(:console_messages)
84
+ puts page.driver.console_messages.find_all { |message| !message.to_s.include? 'mixpanel' }
85
+ puts page.driver.error_messages.find_all { |message| !message.to_s.include? 'mixpanel' }
86
+ end
87
+ screenshot_on_error example
88
+ Capybara.reset_sessions!
89
+ end
90
+
91
+ config.after(:suite) do
92
+ error_screenshot_directory = "spec/error_screenshots/#{ENV["SCREENSHOT_DIR"]}"
93
+ puts "\nError screenshots saved to: #{error_screenshot_directory}" if File.directory?("#{error_screenshot_directory}")
94
+
95
+ # remove any paperclip attachments
96
+ FileUtils.rm_rf(Dir["#{Rails.root}/spec/test_files/"])
97
+ end
98
+ end
@@ -0,0 +1,151 @@
1
+ require 'fileutils'
2
+ require 'open3'
3
+ require 'timeout'
4
+
5
+ RSpec::Matchers.define :become_true do |expected|
6
+
7
+ match do |block|
8
+ end_time = Time.now + Capybara.default_wait_time.seconds
9
+ loop do
10
+ break if Time.now > end_time
11
+ value = block.call
12
+ return true if value
13
+ end
14
+ false
15
+ end
16
+
17
+ def supports_block_expectations?
18
+ true
19
+ end
20
+
21
+ end
22
+
23
+ SnapshotInfo = Struct.new(:name, :variation, :file)
24
+
25
+ class RSpec::Core::ExampleGroup
26
+
27
+ def snapshot(name = :default, variation = :desktop)
28
+ tmp = Tempfile.new([variation, '.png'])
29
+ tmp.close
30
+
31
+ document_width = page.driver.evaluate_script("document.documentElement.clientWidth")
32
+ document_height = page.driver.evaluate_script("document.documentElement.clientHeight")
33
+ page.save_screenshot "#{tmp.path}", width: document_width, height: document_height
34
+
35
+ SnapshotInfo.new(name, variation, tmp)
36
+ end
37
+
38
+ end
39
+
40
+ RSpec.configure do |config|
41
+ config.after(:example) do |example|
42
+ msg = example.metadata[:new_snapshot_paths].inject('') do |msg, path|
43
+ <<-COMMANDS #{msg}
44
+ Show new screenshot:
45
+ $ open #{dirname}/NEW_#{path}
46
+
47
+ Approve new screenshot:
48
+ $ mv #{dirname}/NEW_#{path} #{dirname}/#{path}
49
+ COMMANDS
50
+ end unless example.metadata[:new_snapshot_paths].nil?
51
+
52
+ raise RSpec::Expectations::ExpectationNotMetError, msg, example.metadata[:snapshot_first_caller] unless msg.blank?
53
+ end
54
+
55
+ def dirname
56
+ 'spec/support/expected_snapshots'
57
+ end
58
+
59
+ end
60
+
61
+ RSpec::Matchers.define :look_correct do
62
+ match do |snapshot_info|
63
+
64
+ next true if ENV['SKIP_SCREENSHOT_DIFF']
65
+
66
+ path = snapshot_path(snapshot_info)
67
+
68
+ existing_path = "#{dirname}/#{path}"
69
+ new_path = snapshot_info.file.path
70
+
71
+ existing_height = height_of(existing_path)
72
+ new_height = height_of(new_path)
73
+
74
+ tmpfile_path = Tempfile.new(['scaled','.png']).path if existing_height != new_height
75
+
76
+ if existing_height < new_height
77
+ `convert #{existing_path} -resize 1650x#{new_height} -background black -compose Copy -gravity north -extent 1650x#{new_height} #{tmpfile_path}`
78
+ existing_path = tmpfile_path
79
+ end
80
+
81
+ if new_height < existing_height
82
+ `convert #{new_path} -resize 1650x#{existing_height} -background black -compose Copy -gravity north -extent 1650x#{existing_height} #{tmpfile_path}`
83
+ new_path = tmpfile_path
84
+ end
85
+
86
+
87
+ if File.exists?(existing_path)
88
+ prog = 'compare'
89
+ args = '-verbose -metric RMSE -highlight-color Red'
90
+ diff_path = "#{dirname}/DIFF_#{path}"
91
+
92
+ # do image comparison
93
+ cmd = "#{prog} #{args} \"#{existing_path}\" \"#{new_path}\" \"#{diff_path}\""
94
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
95
+ thr_status = wait_thr.value
96
+
97
+ case thr_status.exitstatus
98
+ when 0
99
+ # remove the diff image since the images match
100
+ FileUtils.rm(diff_path)
101
+ when 1
102
+ # images are different
103
+ FileUtils.mv(snapshot_info.file.path, "#{dirname}/CHANGED_#{path}")
104
+ false
105
+ else
106
+ puts stdout.read
107
+ puts stderr.read
108
+ raise "Diff command failed #{cmd} : (#{thr_status.exitstatus})"
109
+ end
110
+ end
111
+ else
112
+
113
+ # this is a new screenshot, so move it in place
114
+ FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
115
+ FileUtils.mv(snapshot_info.file.path, "#{dirname}/NEW_#{path}")
116
+
117
+ example.metadata[:snapshot_first_caller] = caller unless example.metadata[:snapshot_first_caller]
118
+ (example.metadata[:new_snapshot_paths] ||= []) << path
119
+ end
120
+ end
121
+
122
+ failure_message do |snapshot_info|
123
+ path = snapshot_path(snapshot_info)
124
+
125
+ <<-COMMANDS
126
+ expected that '#{snapshot_info.name}' screenshot for #{snapshot_info.variation} would look correct
127
+
128
+ Show screenshot diffs:
129
+ $ open #{dirname}/DIFF_#{path} #{dirname}/CHANGED_#{path} #{dirname}/#{path}
130
+
131
+ Approve changed screenshot:
132
+ $ mv #{dirname}/CHANGED_#{path} #{dirname}/#{path}
133
+ COMMANDS
134
+ end
135
+
136
+ def dirname
137
+ 'spec/support/expected_snapshots'
138
+ end
139
+
140
+ def snapshot_path(snapshot_info)
141
+ "#{[example.metadata[:full_description].parameterize('-'), snapshot_info.name, snapshot_info.variation].join('_')}.png"
142
+ end
143
+
144
+ def height_of(path)
145
+ `identify -format "%h" #{path}`.chomp.to_i
146
+ end
147
+
148
+ def example
149
+ RSpec.current_example
150
+ end
151
+ end