be_valid_asset 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f5e373c8a93d715175401ab7cf5957d0d25e0b2
4
+ data.tar.gz: af7fd77efaf14d9f6e7a7b66413ceedf5295dbfc
5
+ SHA512:
6
+ metadata.gz: 188b91cfa1a6efe8c6adbcd9e7f54bff0ee1994dbcf00c5fd60223004427a982a5bec7e64445ff400b38595dbdcf3ed95d9c24608d43d38cf6c85011c23bb50f
7
+ data.tar.gz: 45c68a7d767852433d7e452e596eacb2aba14a99f68e679b7a54252253774fcd186d177313f02b8a83faef08f9069cf5b539fc6542e4a4f30e9ad4d41ac4b656
@@ -0,0 +1,49 @@
1
+ # 1.3.0
2
+
3
+ * Use RSpec 3 for development
4
+ * Remove RSpec 3 dep warnings at runtime, while still supporting older RSpecs
5
+ * Support ``BeValidAsset::Configuration.xxx_validator_host`` settings with a protocol
6
+ * Support ``https`` as a protocol for host config
7
+
8
+ # 1.2.3
9
+
10
+ * Use Bundler to manage gem
11
+ * Allow for markup to be modified prior to validation (e.g. to remove attributes you know won't pass)
12
+
13
+ # 1.2.2
14
+
15
+ * Turn off CSS validation warnings about vendor extensions
16
+ * Fix gemspec
17
+
18
+ # 1.2.1
19
+
20
+ * Is broken, use 1.2.2
21
+ * Deprecate ``be_valid_xhtml`` in favour of ``be_valid_markup``
22
+ * Use rspec 2 in development
23
+
24
+ # 1.1.2
25
+
26
+ * Fix because validator response html is different
27
+
28
+ # 1.1.1
29
+
30
+ * Option for displaying context around failed validation
31
+ * Handle empty CSS without getting a 500 from validator
32
+
33
+ # 1.1.0
34
+
35
+ * Added ``be_valid_feed`` for rss/atom by talking to w3c feed validator
36
+
37
+ # 1.0.1
38
+
39
+ * Allow ``be_valid_css`` to take a response object or a string (like ``be_valid_xhtml``).
40
+
41
+ # 1.0.0
42
+
43
+ * Allow to work with Merb
44
+ * Add rspec dependency
45
+
46
+ # 0.9.0
47
+
48
+ * Hello!
49
+ * Provides ``be_valid_css`` and ``be_valid_xhtml`` matchers for rspec to talk to w3c validators.
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in be_valid_asset.gemspec
4
4
  gemspec
5
+ gem 'rake'
6
+ gem 'rspec', '>= 3.0'
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2012 Unboxed Consulting
1
+ Copyright (c) 2009-2014 Unboxed Consulting
2
2
 
3
3
  MIT License
4
4
 
@@ -6,7 +6,7 @@ require 'be_valid_asset/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "be_valid_asset"
8
8
  gem.version = BeValidAsset::VERSION
9
- gem.authors = ["Alex Tomlins", "Attila Gyorffy", "Ben Brinckerhoff", "Jolyon Pawlyn", "Sebastian de Castelberg"]
9
+ gem.authors = ["Alex Tomlins", "Attila Gyorffy", "Ben Brinckerhoff", "Jolyon Pawlyn", "Sebastian de Castelberg", "Zubair Chaudary", "Murray Steele"]
10
10
  gem.email = ["github@unboxedconsulting.com"]
11
11
  gem.description = %q{Provides be_valid_markup, be_valid_css and be_valid_feed matchers for RSpec controller and view tests.}
12
12
  gem.summary = %q{Markup and asset validation for RSpec}
@@ -18,7 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_dependency('rspec')
22
- gem.add_development_dependency('rake')
23
- gem.add_development_dependency('rspec', '>= 2.0')
21
+ gem.add_runtime_dependency('rspec')
24
22
  end
@@ -1,6 +1,8 @@
1
1
 
2
2
  module BeValidAsset
3
3
 
4
+ DontRunValidAssetSpecs = (defined? RSpec::Core::Pending::SkipDeclaredInExample) ? RSpec::Core::Pending::SkipDeclaredInExample : RSpec::Core::Pending::PendingDeclaredInExample
5
+
4
6
  # Abstract base class for other matchers
5
7
  class BeValidBase
6
8
 
@@ -8,7 +10,7 @@ module BeValidAsset
8
10
 
9
11
  def check_net_enabled
10
12
  if ENV["NONET"] == 'true'
11
- raise RSpec::Core::Pending::PendingDeclaredInExample.new('Network tests disabled')
13
+ raise BeValidAsset::DontRunValidAssetSpecs.new('Network tests disabled')
12
14
  end
13
15
  end
14
16
 
@@ -84,14 +86,21 @@ module BeValidAsset
84
86
  ret << "\r\n--#{boundary}--\r\n"
85
87
  ret
86
88
  end
87
-
89
+
88
90
  def http_start(host)
89
- if ENV['http_proxy']
90
- uri = URI.parse(ENV['http_proxy'])
91
- proxy_user, proxy_pass = uri.userinfo.split(/:/) if uri.userinfo
92
- Net::HTTP.start(host, nil, uri.host, uri.port, proxy_user, proxy_pass)
91
+ uri = URI.parse(host)
92
+ uri = URI.parse("http://#{host}") if uri.scheme.nil?
93
+ if uri.scheme == 'https'
94
+ http = Net::HTTP.new uri.host, uri.port
95
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
96
+ http.use_ssl = true
97
+ http.start
98
+ elsif ENV['http_proxy']
99
+ proxy_uri = URI.parse(ENV['http_proxy'])
100
+ proxy_user, proxy_pass = proxy_uri.userinfo.split(/:/) if proxy_uri.userinfo
101
+ Net::HTTP.start(uri.host, uri.port, proxy_uri.host, proxy_uri.port, proxy_user, proxy_pass)
93
102
  else
94
- Net::HTTP.start(host)
103
+ Net::HTTP.start(uri.host, uri.port)
95
104
  end
96
105
  end
97
106
  end
@@ -29,13 +29,15 @@ module BeValidAsset
29
29
  end
30
30
 
31
31
  def failure_message
32
- " expected css to be valid, but validation produced these errors:\n#{@message}"
32
+ " expected css to be valid, but validation produced these errors:\n#{@message}"
33
33
  end
34
-
35
- def negative_failure_message
34
+
35
+ def failure_message_when_negated
36
36
  " expected to not be valid, but was (missing validation?)"
37
37
  end
38
-
38
+ # continue to support Rspec < 3
39
+ alias :negative_failure_message :failure_message_when_negated
40
+
39
41
  private
40
42
 
41
43
  def validator_host
@@ -25,12 +25,14 @@ module BeValidAsset
25
25
  end
26
26
 
27
27
  def failure_message
28
- " expected feed to be valid, but validation produced these errors:\n#{@message}"
28
+ " expected feed to be valid, but validation produced these errors:\n#{@message}"
29
29
  end
30
30
 
31
- def negative_failure_message
31
+ def failure_message_when_negated
32
32
  " expected to not be valid, but was (missing validation?)"
33
33
  end
34
+ # continue to support Rspec < 3
35
+ alias :negative_failure_message :failure_message_when_negated
34
36
 
35
37
  private
36
38
 
@@ -12,13 +12,13 @@ module BeValidAsset
12
12
  Configuration.markup_modifiers = []
13
13
 
14
14
  class BeValidMarkup < BeValidBase
15
-
15
+
16
16
  def initialize(options = {})
17
17
  @fragment = options[:fragment]
18
18
  end
19
-
19
+
20
20
  # Assert that markup (html/xhtml) is valid according the W3C validator web service.
21
-
21
+
22
22
  def matches?(fragment)
23
23
 
24
24
  if fragment.respond_to? :source
@@ -39,22 +39,24 @@ module BeValidAsset
39
39
  query_params[:prefill] = '1'
40
40
  query_params[:prefill_doctype] = 'xhtml10'
41
41
  end
42
-
42
+
43
43
  return validate(query_params)
44
44
  end
45
-
45
+
46
46
  def description
47
47
  "be valid markup"
48
48
  end
49
-
49
+
50
50
  def failure_message
51
- " expected markup to be valid, but validation produced these errors:\n#{@message}"
51
+ " expected markup to be valid, but validation produced these errors:\n#{@message}"
52
52
  end
53
-
54
- def negative_failure_message
53
+
54
+ def failure_message_when_negated
55
55
  " expected to not be valid, but was (missing validation?)"
56
56
  end
57
-
57
+ # continue to support Rspec < 3
58
+ alias :negative_failure_message :failure_message_when_negated
59
+
58
60
  private
59
61
 
60
62
  def apply_modifiers_to_fragment(fragment)
@@ -92,7 +94,7 @@ module BeValidAsset
92
94
  def be_valid_markup
93
95
  BeValidMarkup.new
94
96
  end
95
-
97
+
96
98
  def be_valid_markup_fragment()
97
99
  BeValidMarkup.new(:fragment => true)
98
100
  end
@@ -1,7 +1,7 @@
1
1
  module BeValidAsset
2
-
2
+
3
3
  class BeValidXhtml < BeValidMarkup
4
-
4
+
5
5
  def initialize(options = {})
6
6
  super
7
7
  Kernel.warn('[DEPRECATION] - `be_valid_xhtml` is deprecated, use `be_valid_markup` instead')
@@ -12,7 +12,7 @@ module BeValidAsset
12
12
  BeValidXhtml.new
13
13
  end
14
14
  alias :be_valid_html :be_valid_xhtml
15
-
15
+
16
16
  def be_valid_xhtml_fragment()
17
17
  BeValidXhtml.new(:fragment => true)
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module BeValidAsset
2
- VERSION = "1.2.3"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -4,55 +4,55 @@ unless defined?(SpecFailed)
4
4
  SpecFailed = RSpec::Expectations::ExpectationNotMetError
5
5
  end
6
6
 
7
- describe 'be_valid_css' do
8
-
7
+ RSpec.describe 'be_valid_css' do
8
+
9
9
  describe "without caching" do
10
10
  it "should validate a valid string" do
11
11
  css = get_file('valid.css')
12
- css.should be_valid_css
12
+ expect(css).to be_valid_css
13
13
  end
14
-
14
+
15
15
  it "should validate an empty string" do
16
- ''.should be_valid_css
16
+ expect('').to be_valid_css
17
17
  end
18
18
 
19
19
  it "should validate a valid response" do
20
20
  response = MockResponse.new(get_file('valid.css'))
21
- response.should be_valid_css
21
+ expect(response).to be_valid_css
22
22
  end
23
23
 
24
24
  it "should validate if body is not a string but can be converted to valid string" do
25
- response = MockResponse.new(stub("CSS", :to_s => get_file('valid.css')))
26
- response.should be_valid_css
25
+ response = MockResponse.new(double("CSS", :to_s => get_file('valid.css')))
26
+ expect(response).to be_valid_css
27
27
  end
28
28
 
29
29
  it "should not validate an invalid string" do
30
30
  css = get_file('invalid.css')
31
- lambda {
32
- css.should be_valid_css
33
- }.should raise_error(SpecFailed) { |e|
34
- e.message.should match(/expected css to be valid, but validation produced these errors/)
35
- e.message.should match(/Invalid css: line 8: Property wibble doesn't exist/)
31
+ expect {
32
+ expect(css).to be_valid_css
33
+ }.to raise_error(SpecFailed) { |e|
34
+ expect(e.message).to match(/expected css to be valid, but validation produced these errors/)
35
+ expect(e.message).to match(/Invalid css: line 8: Property wibble doesn't exist/)
36
36
  }
37
37
  end
38
38
 
39
39
  it "should not validate an invalid response" do
40
40
  response = MockResponse.new(get_file('invalid.css'))
41
- lambda {
42
- response.should be_valid_css
43
- }.should raise_error(SpecFailed) { |e|
44
- e.message.should match(/expected css to be valid, but validation produced these errors/)
45
- e.message.should match(/Invalid css: line 8: Property wibble doesn't exist/)
41
+ expect {
42
+ expect(response).to be_valid_css
43
+ }.to raise_error(SpecFailed) { |e|
44
+ expect(e.message).to match(/expected css to be valid, but validation produced these errors/)
45
+ expect(e.message).to match(/Invalid css: line 8: Property wibble doesn't exist/)
46
46
  }
47
47
  end
48
48
 
49
49
  it "should display invalid content when requested" do
50
50
  BeValidAsset::Configuration.display_invalid_content = true
51
51
  css = get_file('invalid.css')
52
- lambda {
53
- css.should be_valid_css
54
- }.should raise_error(SpecFailed) { |e|
55
- e.message.should match(/wibble:0;/)
52
+ expect {
53
+ expect(css).to be_valid_css
54
+ }.to raise_error(SpecFailed) { |e|
55
+ expect(e.message).to match(/wibble:0;/)
56
56
  }
57
57
  BeValidAsset::Configuration.display_invalid_content = false
58
58
  end
@@ -62,21 +62,21 @@ describe 'be_valid_css' do
62
62
 
63
63
  r = Net::HTTPServiceUnavailable.new('1.1', 503, 'Service Unavailable')
64
64
  h = Net::HTTP.new(BeValidAsset::Configuration.css_validator_host)
65
- h.stub!(:post2).and_return(r)
66
- Net::HTTP.stub!(:start).and_return(h)
65
+ allow(h).to receive(:post2).and_return(r)
66
+ allow(Net::HTTP).to receive(:start).and_return(h)
67
67
 
68
- lambda {
69
- css.should be_valid_css
70
- }.should raise_error
68
+ expect {
69
+ expect(css).to be_valid_css
70
+ }.to raise_error
71
71
  end
72
72
 
73
73
  it "should mark test as pending if ENV['NONET'] is true" do
74
74
  ENV['NONET'] = 'true'
75
75
 
76
76
  css = get_file('valid.css')
77
- lambda {
78
- css.should be_valid_css
79
- }.should raise_error(RSpec::Core::Pending::PendingDeclaredInExample)
77
+ expect {
78
+ expect(css).to be_valid_css
79
+ }.to raise_error(BeValidAsset::DontRunValidAssetSpecs)
80
80
 
81
81
  ENV.delete('NONET')
82
82
  end
@@ -90,13 +90,13 @@ describe 'be_valid_css' do
90
90
  (1..3).each do |test_version|
91
91
  if test_version < version
92
92
  it "should not be valid css#{test_version.to_s}" do
93
- lambda {
94
- @css.should send("be_valid_css#{test_version.to_s}".to_sym)
95
- }.should raise_error(SpecFailed)
93
+ expect {
94
+ expect(@css).to send("be_valid_css#{test_version.to_s}".to_sym)
95
+ }.to raise_error(SpecFailed)
96
96
  end
97
97
  else
98
98
  it "should be valid css#{test_version.to_s}" do
99
- @css.should send("be_valid_css#{test_version.to_s}".to_sym)
99
+ expect(@css).to send("be_valid_css#{test_version.to_s}".to_sym)
100
100
  end
101
101
  end
102
102
  end
@@ -104,7 +104,7 @@ describe 'be_valid_css' do
104
104
  end
105
105
  end
106
106
  end
107
-
107
+
108
108
  describe "with caching" do
109
109
  before(:each) do
110
110
  BeValidAsset::Configuration.enable_caching = true
@@ -117,40 +117,40 @@ describe 'be_valid_css' do
117
117
  it "should validate valid css and cache the response" do
118
118
  css = get_file('valid.css')
119
119
  count = Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size
120
- css.should be_valid_css
121
- Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.should eql(count + 1)
120
+ expect(css).to be_valid_css
121
+ expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count + 1)
122
122
  end
123
123
 
124
124
  it "should validate valid css using the cached response" do
125
125
  css = get_file('valid.css')
126
- css.should be_valid_css
126
+ expect(css).to be_valid_css
127
127
 
128
- Net::HTTP.should_not_receive(:start)
129
- css.should be_valid_css
128
+ expect(Net::HTTP).not_to receive(:start)
129
+ expect(css).to be_valid_css
130
130
  end
131
131
 
132
132
  it "should not validate invalid css, but still cache the response" do
133
133
  css = get_file('invalid.css')
134
134
  count = Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size
135
- lambda {
136
- css.should be_valid_css
137
- }.should raise_error(SpecFailed) { |e|
138
- e.message.should match(/expected css to be valid, but validation produced these errors/)
139
- e.message.should match(/Invalid css: line 8: Property wibble doesn't exist/)
135
+ expect {
136
+ expect(css).to be_valid_css
137
+ }.to raise_error(SpecFailed) { |e|
138
+ expect(e.message).to match(/expected css to be valid, but validation produced these errors/)
139
+ expect(e.message).to match(/Invalid css: line 8: Property wibble doesn't exist/)
140
140
  }
141
- Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.should eql(count + 1)
141
+ expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count + 1)
142
142
  end
143
143
 
144
144
  it "should not validate invalid css, but use the cached response" do
145
145
  css = get_file('invalid.css')
146
- css.should_not be_valid_css
147
-
148
- Net::HTTP.should_not_receive(:start)
149
- lambda {
150
- css.should be_valid_css
151
- }.should raise_error(SpecFailed) { |e|
152
- e.message.should match(/expected css to be valid, but validation produced these errors/)
153
- e.message.should match(/Invalid css: line 8: Property wibble doesn't exist/)
146
+ expect(css).not_to be_valid_css
147
+
148
+ expect(Net::HTTP).not_to receive(:start)
149
+ expect {
150
+ expect(css).to be_valid_css
151
+ }.to raise_error(SpecFailed) { |e|
152
+ expect(e.message).to match(/expected css to be valid, but validation produced these errors/)
153
+ expect(e.message).to match(/Invalid css: line 8: Property wibble doesn't exist/)
154
154
  }
155
155
  end
156
156
 
@@ -160,23 +160,23 @@ describe 'be_valid_css' do
160
160
 
161
161
  r = Net::HTTPServiceUnavailable.new('1.1', 503, 'Service Unavailable')
162
162
  h = Net::HTTP.new(BeValidAsset::Configuration.css_validator_host)
163
- h.stub!(:post2).and_return(r)
164
- Net::HTTP.stub!(:start).and_return(h)
163
+ allow(h).to receive(:post2).and_return(r)
164
+ allow(Net::HTTP).to receive(:start).and_return(h)
165
165
 
166
- lambda {
167
- css.should be_valid_css
168
- }.should raise_error
169
- Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size.should eql(count)
166
+ expect {
167
+ expect(css).to be_valid_css
168
+ }.to raise_error
169
+ expect(Dir.glob(BeValidAsset::Configuration.cache_path + '/*').size).to eql(count)
170
170
  end
171
171
 
172
172
  it "should use the cached result (if available) when network tests disabled" do
173
173
  css = get_file('valid.css')
174
- css.should be_valid_css
174
+ expect(css).to be_valid_css
175
175
 
176
176
  ENV['NONET'] = 'true'
177
177
 
178
- Net::HTTP.should_not_receive(:start)
179
- css.should be_valid_css
178
+ expect(Net::HTTP).not_to receive(:start)
179
+ expect(css).to be_valid_css
180
180
 
181
181
  ENV.delete('NONET')
182
182
  end
@@ -185,9 +185,9 @@ describe 'be_valid_css' do
185
185
  ENV['NONET'] = 'true'
186
186
 
187
187
  css = get_file('valid.css')
188
- lambda {
189
- css.should be_valid_css
190
- }.should raise_error(RSpec::Core::Pending::PendingDeclaredInExample)
188
+ expect {
189
+ expect(css).to be_valid_css
190
+ }.to raise_error(BeValidAsset::DontRunValidAssetSpecs)
191
191
 
192
192
  ENV.delete('NONET')
193
193
  end