be_valid_asset 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/{spec/spec.opts → .rspec} +0 -0
- data/Gemfile +4 -0
- data/{MIT-LICENSE.txt → LICENSE.txt} +3 -1
- data/README.md +192 -0
- data/Rakefile +5 -16
- data/be_valid_asset.gemspec +24 -0
- data/lib/be_valid_asset.rb +2 -29
- data/lib/be_valid_asset/be_valid_markup.rb +24 -1
- data/lib/be_valid_asset/configuration.rb +27 -0
- data/lib/be_valid_asset/version.rb +3 -0
- data/spec/be_valid_asset/be_valid_markup_spec.rb +34 -0
- data/spec/files/html_with_srcset.html +14 -0
- data/spec/files/html_without_srcset.html +14 -0
- data/spec/files/valid_with_cache_busters.html +16 -0
- data/spec/files/valid_without_cache_busters.html +16 -0
- metadata +88 -16
- data/README.markdown +0 -158
data/.gitignore
ADDED
data/{spec/spec.opts → .rspec}
RENAMED
File without changes
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
# be_valid_asset
|
2
|
+
|
3
|
+
Provides `be_valid_markup`, `be_valid_css` and `be_valid_feed` matchers for RSpec controller and view tests.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To use be_valid_asset in your project, add it to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'be_valid_asset'
|
11
|
+
```
|
12
|
+
|
13
|
+
Alternatively you can install it as a Rails plugin:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
./script/plugin install git://github.com/unboxed/be_valid_asset.git
|
17
|
+
```
|
18
|
+
|
19
|
+
(Warning: This method is not recommended, we strongly encourage you to manage gem dependencies via [Bundler](http://gembundler.com/))
|
20
|
+
|
21
|
+
Add the following to `spec/support/be_valid_asset.rb`:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
include BeValidAsset
|
25
|
+
|
26
|
+
BeValidAsset::Configuration.display_invalid_content = true
|
27
|
+
BeValidAsset::Configuration.enable_caching = true
|
28
|
+
BeValidAsset::Configuration.cache_path = Rails.root.join('tmp', 'be_valid_asset_cache')
|
29
|
+
```
|
30
|
+
|
31
|
+
Note: For older versions of RSpec you'll need to require `be_valid_asset.rb` from `spec_helper.rb`.
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
### Markup validation
|
36
|
+
|
37
|
+
It can be used to test a Capybara Session object in a request spec as follows:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
scenario "Visiting foo and validate markup" do
|
41
|
+
visit foo_path
|
42
|
+
page.should be_valid_markup
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
or an ActionController Response object:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
describe FooController do
|
50
|
+
render_views
|
51
|
+
|
52
|
+
describe "GET 'index'" do
|
53
|
+
it "renders valid markup" do
|
54
|
+
get :index
|
55
|
+
response.should be_valid_markup
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
or to test a string:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
it "is valid markup" do
|
65
|
+
html = File.read(Rails.root.join('public', 'index.html'))
|
66
|
+
html.should be_valid_markup
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
It is also possible to validate an html fragment. This assumes xhtml-1.0 strict.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
it "is valid HTML" do
|
74
|
+
string = "<p>This is an html fragment</p>"
|
75
|
+
string.should be_valid_markup_fragment
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
### CSS validation
|
80
|
+
|
81
|
+
CSS files can be validated as follows:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
it "is valid CSS" do
|
85
|
+
css = File.read(Rails.root.join('public', 'stylesheets', 'main.css'))
|
86
|
+
css.should be_valid_css
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
be_valid_css takes an optional parameter specifying the CSS profile to test against. It defaults to testing against CSS 2.1. It can be set to any of the profiles supported by the CSS validator (e.g. css1, css2, css21, css3). There are also the following shortcut methods:
|
91
|
+
|
92
|
+
* `be_valid_css1` => CSS 1.0
|
93
|
+
* `be_valid_css2` => CSS 2.1
|
94
|
+
* `be_valid_css3` => CSS 3.0
|
95
|
+
|
96
|
+
### Feed validation
|
97
|
+
|
98
|
+
RSS and Atom feeds can be validated from a response, or a string, in the same way as for html or CSS. e.g.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
describe FooController do
|
102
|
+
render_views
|
103
|
+
|
104
|
+
describe "GET 'index.rss'" do
|
105
|
+
it "is a valid feed" do
|
106
|
+
get 'index.rss'
|
107
|
+
response.should be_valid_feed
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
There are also aliased methods `be_valid_rss` and `be_valid_atom` that do the same thing.
|
114
|
+
|
115
|
+
## Environment Variables
|
116
|
+
|
117
|
+
### Disabling network tests
|
118
|
+
|
119
|
+
If the environment variable `NONET` is set to true, then all tests with no cached response available will be marked as pending.
|
120
|
+
|
121
|
+
### http_proxy
|
122
|
+
|
123
|
+
If you need to use a proxy server to access the validator service, set the environment variable http_proxy.
|
124
|
+
|
125
|
+
## Configuration options
|
126
|
+
|
127
|
+
The following can be set in `spec/support/be_valid_asset.rb`:
|
128
|
+
|
129
|
+
### Display Full source for failures:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
BeValidAsset::Configuration.display_invalid_content = false
|
133
|
+
# defaults to false
|
134
|
+
```
|
135
|
+
|
136
|
+
### Display surrounding source for failures:
|
137
|
+
|
138
|
+
This will cause it to output the failing line, and n surrounding lines (defaults to 5)
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
BeValidAsset::Configuration.display_invalid_lines = true
|
142
|
+
BeValidAsset::Configuration.display_invalid_lines_count = 10
|
143
|
+
# defaults to false and 5 lines
|
144
|
+
```
|
145
|
+
|
146
|
+
### Change validator host/path:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
BeValidAsset::Configuration.markup_validator_host = 'validator.w3.org'
|
150
|
+
BeValidAsset::Configuration.markup_validator_path = '/check'
|
151
|
+
BeValidAsset::Configuration.css_validator_host = 'jigsaw.w3.org'
|
152
|
+
BeValidAsset::Configuration.css_validator_path = '/css-validator/validator'
|
153
|
+
BeValidAsset::Configuration.feed_validator_host = 'validator.w3.org'
|
154
|
+
BeValidAsset::Configuration.feed_validator_path = '/feed/check.cgi'
|
155
|
+
```
|
156
|
+
|
157
|
+
If you are doing more than the occasional check, you should run your own copy of the validator, and use that.
|
158
|
+
|
159
|
+
Instructions here: [http://validator.w3.org/docs/install.html](http://validator.w3.org/docs/install.html), [http://jigsaw.w3.org/css-validator/DOWNLOAD.html](http://jigsaw.w3.org/css-validator/DOWNLOAD.html) or [https://github.com/w3c/css-validator-standalone](https://github.com/w3c/css-validator-standalone) and [http://validator.w3.org/feed/about.html#where](http://validator.w3.org/feed/about.html#where)
|
160
|
+
|
161
|
+
### Caching
|
162
|
+
|
163
|
+
be_valid_asset can cache the responses from the validator to save look-ups for documents that haven't changed. To use this feature, it must be enabled, and a cache path must be set:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
BeValidAsset::Configuration.enable_caching = true
|
167
|
+
BeValidAsset::Configuration.cache_path = Rails.root.join('tmp', 'be_valid_asset_cache')
|
168
|
+
```
|
169
|
+
|
170
|
+
By default, cache busters for `href` and `src` attribute values are stripped like `src="/images/test.jpg?8171717"` is cached as `src="/images/test.jpg"`. If this is unwanted, add the following to the configuration file:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
BeValidAsset::Configuration.markup_cache_modifiers = []
|
174
|
+
```
|
175
|
+
|
176
|
+
### Markup modification prior to validation
|
177
|
+
|
178
|
+
There might be specific parts of your markup that have not yet been standardised and you still want to validate the rest of your markup. There may be elements of your markup that causes validation to fail. If you want to ignore specific markup that causes failures but validate the rest, regular expressions can be used to modify the markup prior to validation. Ideally this would not be necessary, but with emerging standards like the [HTML Responsive Images Extension](http://dvcs.w3.org/hg/html-proposals/raw-file/tip/responsive-images/responsive-images.html) sometimes it is potentially the best solution until the markup validator is updated. If you are using the `srcset` attribute on an `img` tag and want to remove it prior to validation, set the configuration as shown below. `markup_modifiers` is a 2 dimensional array, where each constituent array has two elements that provide the arguments to a call to [`gsub`](http://www.ruby-doc.org/core-1.9.3/String.html#method-i-gsub).
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
BeValidAsset::Configuration.markup_modifiers = [[/ srcset=".* \dx"/, '']]
|
182
|
+
```
|
183
|
+
|
184
|
+
## Issues / Feature Requests
|
185
|
+
|
186
|
+
Please use the [Github issue tracker](http://github.com/unboxed/be_valid_asset/issues) to track any bugs/feature requests.
|
187
|
+
|
188
|
+
## Licensing
|
189
|
+
|
190
|
+
This was originally based on a blog post here: [http://www.anodyne.ca/2007/09/28/rspec-custom-matchers-and-be\_valid\_xhtml/](http://www.anodyne.ca/2007/09/28/rspec-custom-matchers-and-be_valid_xhtml/)
|
191
|
+
|
192
|
+
This is distributed under the MIT Licence, see `LICENSE.txt` for the details.
|
data/Rakefile
CHANGED
@@ -1,18 +1,7 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'rspec/core/rake_task'
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
4
3
|
|
5
|
-
|
6
|
-
task :default => :spec
|
7
|
-
RSpec::Core::RakeTask.new do |spec|
|
8
|
-
spec.rspec_opts = ['--options', File.join(File.dirname(__FILE__), %w(spec spec.opts))]
|
9
|
-
end
|
4
|
+
RSpec::Core::RakeTask.new('spec')
|
10
5
|
|
11
|
-
#
|
12
|
-
|
13
|
-
# rdoc.rdoc_dir = 'rdoc'
|
14
|
-
# rdoc.title = 'BeValidAsset'
|
15
|
-
# rdoc.options << '--line-numbers' << '--inline-source'
|
16
|
-
# rdoc.rdoc_files.include('README')
|
17
|
-
# rdoc.rdoc_files.include('lib/**/*.rb')
|
18
|
-
# end
|
6
|
+
# Run RSpec code examples as the default rake task
|
7
|
+
task :default => :spec
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'be_valid_asset/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "be_valid_asset"
|
8
|
+
gem.version = BeValidAsset::VERSION
|
9
|
+
gem.authors = ["Alex Tomlins", "Attila Gyorffy", "Ben Brinckerhoff", "Jolyon Pawlyn", "Sebastian de Castelberg"]
|
10
|
+
gem.email = ["github@unboxedconsulting.com"]
|
11
|
+
gem.description = %q{Provides be_valid_markup, be_valid_css and be_valid_feed matchers for RSpec controller and view tests.}
|
12
|
+
gem.summary = %q{Markup and asset validation for RSpec}
|
13
|
+
gem.homepage = "http://github.com/unboxed/be_valid_asset"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency('rspec')
|
22
|
+
gem.add_development_dependency('rake')
|
23
|
+
gem.add_development_dependency('rspec', '>= 2.0')
|
24
|
+
end
|
data/lib/be_valid_asset.rb
CHANGED
@@ -1,32 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
@@config = {
|
4
|
-
:display_invalid_content => false,
|
5
|
-
:enable_caching => false,
|
6
|
-
:display_invalid_lines => false,
|
7
|
-
:display_invalid_lines_count => 5
|
8
|
-
}
|
9
|
-
|
10
|
-
def self.method_missing(name, *args)
|
11
|
-
if name.to_s =~ /^(.*)=$/
|
12
|
-
@@config[$1.to_sym] = args[0]
|
13
|
-
elsif @@config.has_key?(name)
|
14
|
-
return @@config[name]
|
15
|
-
else
|
16
|
-
super
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.cache_path=(path)
|
21
|
-
@@config[:cache_path] = path
|
22
|
-
unless File.directory? path
|
23
|
-
FileUtils.mkdir_p path
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
1
|
+
require 'be_valid_asset/version'
|
2
|
+
require 'be_valid_asset/configuration'
|
30
3
|
require 'be_valid_asset/be_valid_base'
|
31
4
|
require 'be_valid_asset/be_valid_markup'
|
32
5
|
require 'be_valid_asset/be_valid_xhtml'
|
@@ -8,6 +8,8 @@ module BeValidAsset
|
|
8
8
|
|
9
9
|
Configuration.markup_validator_host = 'validator.w3.org'
|
10
10
|
Configuration.markup_validator_path = '/check'
|
11
|
+
Configuration.markup_cache_modifiers = [[/(href=".*?)\?\d+/, '\1'], [/(src=".*?)\?\d+/, '\1']]
|
12
|
+
Configuration.markup_modifiers = []
|
11
13
|
|
12
14
|
class BeValidMarkup < BeValidBase
|
13
15
|
|
@@ -24,7 +26,9 @@ module BeValidAsset
|
|
24
26
|
elsif fragment.respond_to? :body
|
25
27
|
fragment = fragment.body.to_s
|
26
28
|
end
|
27
|
-
|
29
|
+
|
30
|
+
fragment = apply_modifiers_to_fragment(fragment)
|
31
|
+
|
28
32
|
if fragment.empty?
|
29
33
|
@message = "Response was blank (maybe a missing integrate_views)"
|
30
34
|
return false
|
@@ -53,6 +57,25 @@ module BeValidAsset
|
|
53
57
|
|
54
58
|
private
|
55
59
|
|
60
|
+
def apply_modifiers_to_fragment(fragment)
|
61
|
+
if (Configuration.enable_caching && ! Configuration.markup_cache_modifiers.empty?) or ! Configuration.markup_modifiers.empty?
|
62
|
+
fragment = fragment.dup
|
63
|
+
end
|
64
|
+
|
65
|
+
if Configuration.enable_caching && ! Configuration.markup_cache_modifiers.empty?
|
66
|
+
Configuration.markup_cache_modifiers.each do |replacement|
|
67
|
+
fragment.gsub!(replacement[0], replacement[1])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if ! Configuration.markup_modifiers.empty?
|
72
|
+
Configuration.markup_modifiers.each do |replacement|
|
73
|
+
fragment.gsub!(replacement[0], replacement[1])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
fragment
|
77
|
+
end
|
78
|
+
|
56
79
|
def validator_host
|
57
80
|
Configuration.markup_validator_host
|
58
81
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module BeValidAsset
|
2
|
+
class Configuration
|
3
|
+
@@config = {
|
4
|
+
:display_invalid_content => false,
|
5
|
+
:enable_caching => false,
|
6
|
+
:display_invalid_lines => false,
|
7
|
+
:display_invalid_lines_count => 5
|
8
|
+
}
|
9
|
+
|
10
|
+
def self.method_missing(name, *args)
|
11
|
+
if name.to_s =~ /^(.*)=$/
|
12
|
+
@@config[$1.to_sym] = args[0]
|
13
|
+
elsif @@config.has_key?(name)
|
14
|
+
return @@config[name]
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.cache_path=(path)
|
21
|
+
@@config[:cache_path] = path
|
22
|
+
unless File.directory? path
|
23
|
+
FileUtils.mkdir_p path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -261,6 +261,40 @@ describe 'be_valid_markup' do
|
|
261
261
|
|
262
262
|
ENV.delete('NONET')
|
263
263
|
end
|
264
|
+
|
265
|
+
describe "with default modifiers" do
|
266
|
+
it "should strip off cache busters for href and src attributes" do
|
267
|
+
html = get_file('valid_with_cache_busters.html')
|
268
|
+
html_modified = get_file('valid_without_cache_busters.html')
|
269
|
+
be_valid_markup = BeValidAsset::BeValidMarkup.new
|
270
|
+
be_valid_markup.should_receive(:validate).with({:fragment => html_modified})
|
271
|
+
be_valid_markup.matches?(html)
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should not strip off cache busters if caching isn't enabled" do
|
275
|
+
BeValidAsset::Configuration.enable_caching = false
|
276
|
+
html = get_file('valid_with_cache_busters.html')
|
277
|
+
be_valid_markup = BeValidAsset::BeValidMarkup.new
|
278
|
+
be_valid_markup.should_receive(:validate).with({:fragment => html})
|
279
|
+
be_valid_markup.matches?(html)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
describe "markup modification" do
|
285
|
+
before :each do
|
286
|
+
BeValidAsset::Configuration.markup_modifiers = [[/ srcset=".*"/, '']]
|
287
|
+
end
|
288
|
+
after :each do
|
289
|
+
BeValidAsset::Configuration.markup_modifiers = []
|
290
|
+
end
|
291
|
+
it "should apply modification" do
|
292
|
+
html = get_file('html_with_srcset.html')
|
293
|
+
html_modified = get_file('html_without_srcset.html')
|
294
|
+
be_valid_markup = BeValidAsset::BeValidMarkup.new
|
295
|
+
be_valid_markup.should_receive(:validate).with({:fragment => html_modified})
|
296
|
+
be_valid_markup.matches?(html)
|
297
|
+
end
|
264
298
|
end
|
265
299
|
|
266
300
|
describe "Proxying" do
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Test Valid Page</title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Test#valid</h1>
|
11
|
+
<img src="/images/test.jpg" alt="test" srcset="/images/test.jpg">
|
12
|
+
<br>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Test Valid Page</title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Test#valid</h1>
|
11
|
+
<img src="/images/test.jpg" alt="test">
|
12
|
+
<br>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Test Valid Page</title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Test#valid</h1>
|
11
|
+
<p>This is an example valid html5 file</p>
|
12
|
+
<a href="/testing?655557777">Test link</a>
|
13
|
+
<img src="/images/test.jpg?123456" alt="test">
|
14
|
+
<br>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
5
|
+
<title>Test Valid Page</title>
|
6
|
+
</head>
|
7
|
+
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<h1>Test#valid</h1>
|
11
|
+
<p>This is an example valid html5 file</p>
|
12
|
+
<a href="/testing">Test link</a>
|
13
|
+
<img src="/images/test.jpg" alt="test">
|
14
|
+
<br>
|
15
|
+
</body>
|
16
|
+
</html>
|
metadata
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: be_valid_asset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alex Tomlins
|
9
|
-
-
|
9
|
+
- Attila Gyorffy
|
10
10
|
- Ben Brinckerhoff
|
11
|
+
- Jolyon Pawlyn
|
12
|
+
- Sebastian de Castelberg
|
11
13
|
autorequire:
|
12
14
|
bindir: bin
|
13
15
|
cert_chain: []
|
14
|
-
date: 2012-
|
16
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
15
17
|
dependencies:
|
16
18
|
- !ruby/object:Gem::Dependency
|
17
19
|
name: rspec
|
18
|
-
requirement:
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
19
21
|
none: false
|
20
22
|
requirements:
|
21
23
|
- - ! '>='
|
@@ -23,27 +25,72 @@ dependencies:
|
|
23
25
|
version: '0'
|
24
26
|
type: :runtime
|
25
27
|
prerelease: false
|
26
|
-
version_requirements:
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rake
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
type: :development
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec
|
52
|
+
requirement: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.0'
|
58
|
+
type: :development
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '2.0'
|
66
|
+
description: Provides be_valid_markup, be_valid_css and be_valid_feed matchers for
|
67
|
+
RSpec controller and view tests.
|
68
|
+
email:
|
69
|
+
- github@unboxedconsulting.com
|
30
70
|
executables: []
|
31
71
|
extensions: []
|
32
72
|
extra_rdoc_files: []
|
33
73
|
files:
|
74
|
+
- .gitignore
|
75
|
+
- .rspec
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
34
79
|
- Rakefile
|
35
|
-
-
|
36
|
-
-
|
80
|
+
- be_valid_asset.gemspec
|
81
|
+
- lib/be_valid_asset.rb
|
37
82
|
- lib/be_valid_asset/be_valid_base.rb
|
38
83
|
- lib/be_valid_asset/be_valid_css.rb
|
39
84
|
- lib/be_valid_asset/be_valid_feed.rb
|
40
85
|
- lib/be_valid_asset/be_valid_markup.rb
|
41
86
|
- lib/be_valid_asset/be_valid_xhtml.rb
|
42
|
-
- lib/be_valid_asset.rb
|
87
|
+
- lib/be_valid_asset/configuration.rb
|
88
|
+
- lib/be_valid_asset/version.rb
|
43
89
|
- spec/be_valid_asset/be_valid_css_spec.rb
|
44
90
|
- spec/be_valid_asset/be_valid_feed_spec.rb
|
45
91
|
- spec/be_valid_asset/be_valid_markup_spec.rb
|
46
|
-
- spec/
|
92
|
+
- spec/files/html_with_srcset.html
|
93
|
+
- spec/files/html_without_srcset.html
|
47
94
|
- spec/files/invalid.css
|
48
95
|
- spec/files/invalid.html
|
49
96
|
- spec/files/invalid2.html
|
@@ -55,9 +102,12 @@ files:
|
|
55
102
|
- spec/files/valid.html
|
56
103
|
- spec/files/valid.html5
|
57
104
|
- spec/files/valid_feed.xml
|
58
|
-
- spec/
|
105
|
+
- spec/files/valid_with_cache_busters.html
|
106
|
+
- spec/files/valid_without_cache_busters.html
|
107
|
+
- spec/spec_helper.rb
|
59
108
|
homepage: http://github.com/unboxed/be_valid_asset
|
60
|
-
licenses:
|
109
|
+
licenses:
|
110
|
+
- MIT
|
61
111
|
post_install_message:
|
62
112
|
rdoc_options: []
|
63
113
|
require_paths:
|
@@ -68,19 +118,41 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
118
|
- - ! '>='
|
69
119
|
- !ruby/object:Gem::Version
|
70
120
|
version: '0'
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
hash: -4532398578737053975
|
71
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
125
|
none: false
|
73
126
|
requirements:
|
74
127
|
- - ! '>='
|
75
128
|
- !ruby/object:Gem::Version
|
76
129
|
version: '0'
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
hash: -4532398578737053975
|
77
133
|
requirements: []
|
78
134
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.8.
|
135
|
+
rubygems_version: 1.8.23
|
80
136
|
signing_key:
|
81
137
|
specification_version: 3
|
82
|
-
summary: Markup validation for RSpec
|
138
|
+
summary: Markup and asset validation for RSpec
|
83
139
|
test_files:
|
84
140
|
- spec/be_valid_asset/be_valid_css_spec.rb
|
85
141
|
- spec/be_valid_asset/be_valid_feed_spec.rb
|
86
142
|
- spec/be_valid_asset/be_valid_markup_spec.rb
|
143
|
+
- spec/files/html_with_srcset.html
|
144
|
+
- spec/files/html_without_srcset.html
|
145
|
+
- spec/files/invalid.css
|
146
|
+
- spec/files/invalid.html
|
147
|
+
- spec/files/invalid2.html
|
148
|
+
- spec/files/invalid_feed.xml
|
149
|
+
- spec/files/valid-1.css
|
150
|
+
- spec/files/valid-2.css
|
151
|
+
- spec/files/valid-3.css
|
152
|
+
- spec/files/valid.css
|
153
|
+
- spec/files/valid.html
|
154
|
+
- spec/files/valid.html5
|
155
|
+
- spec/files/valid_feed.xml
|
156
|
+
- spec/files/valid_with_cache_busters.html
|
157
|
+
- spec/files/valid_without_cache_busters.html
|
158
|
+
- spec/spec_helper.rb
|
data/README.markdown
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
be\_valid\_asset
|
2
|
-
==============
|
3
|
-
|
4
|
-
Provides `be_valid_markup`, `be_valid_css` and `be_valid_feed` matchers for rspec controller and view tests.
|
5
|
-
|
6
|
-
Installation
|
7
|
-
------------
|
8
|
-
|
9
|
-
To use be\_valid\_asset in your project, install the gem:
|
10
|
-
|
11
|
-
gem install be_valid_asset
|
12
|
-
|
13
|
-
or install as a plugin
|
14
|
-
|
15
|
-
./script/plugin install git://github.com/unboxed/be_valid_asset.git
|
16
|
-
|
17
|
-
Add the following to the `spec/support/be_valid_asset.rb`:
|
18
|
-
(for older versions of RSpec you'll need to require it from `spec_helper.rb`)
|
19
|
-
|
20
|
-
include BeValidAsset
|
21
|
-
|
22
|
-
# BeValidAsset::Configuration.display_invalid_content = true
|
23
|
-
BeValidAsset::Configuration.enable_caching = true
|
24
|
-
BeValidAsset::Configuration.cache_path = File.join(RAILS_ROOT, %w(tmp be_valid_asset_cache))
|
25
|
-
|
26
|
-
See below for details of the configuration options available
|
27
|
-
|
28
|
-
Usage
|
29
|
-
-----
|
30
|
-
|
31
|
-
### Markup validation
|
32
|
-
|
33
|
-
It can be used to test either an ActionController Response object as follows:
|
34
|
-
|
35
|
-
describe FooController do
|
36
|
-
integrate_views
|
37
|
-
|
38
|
-
describe "GET 'index'" do
|
39
|
-
it "should have valid markup" do
|
40
|
-
get 'index'
|
41
|
-
response.should be_valid_markup
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
or
|
47
|
-
|
48
|
-
describe "/index.html" do
|
49
|
-
it "should be valid markup" do
|
50
|
-
render 'home/index', :layout => true
|
51
|
-
response.should be_valid_markup
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
or to test a string:
|
56
|
-
|
57
|
-
it "should be valid markup" do
|
58
|
-
html = File.read(File.join(RAILS_ROOT, %w(public index.html)))
|
59
|
-
html.should be_valid_markup
|
60
|
-
end
|
61
|
-
|
62
|
-
It is also possible to validate an html fragment. This assumes xhtml-1.0 strict.
|
63
|
-
|
64
|
-
it "should be valid html" do
|
65
|
-
string = "<p>This is an html fragment</p>"
|
66
|
-
string.should be_valid_markup_fragment
|
67
|
-
end
|
68
|
-
|
69
|
-
### CSS validation
|
70
|
-
|
71
|
-
CSS files can be validated as follows:
|
72
|
-
|
73
|
-
it "should be valid CSS" do
|
74
|
-
css = File.read(File.join(RAILS_ROOT, %w(public stylesheets main.css)))
|
75
|
-
css.should be_valid_css
|
76
|
-
end
|
77
|
-
|
78
|
-
be\_valid\_css takes an optional parameter specifying the css profile to test against. It defaults to testing against CSS 2.1. It can be set to any of the profiles supported by the CSS validator (e.g. css1, css2, css21, css3). There are also the following shortcut methods:
|
79
|
-
|
80
|
-
* `be_valid_css1` => CSS 1.0
|
81
|
-
* `be_valid_css2` => CSS 2.1
|
82
|
-
* `be_valid_css3` => CSS 3.0
|
83
|
-
|
84
|
-
### Feed validation
|
85
|
-
|
86
|
-
RSS and Atom feeds can be validated from a response, or a string, in the same way as for html or CSS. e.g.
|
87
|
-
|
88
|
-
describe FooController do
|
89
|
-
integrate_views
|
90
|
-
|
91
|
-
describe "GET 'index.rss'" do
|
92
|
-
it "should be valid" do
|
93
|
-
get 'index.rss'
|
94
|
-
response.should be_valid_feed
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
There are also aliased methods `be_valid_rss` and `be_valid_atom` that do the same thing.
|
100
|
-
|
101
|
-
Environment Variables
|
102
|
-
---------------------
|
103
|
-
|
104
|
-
### Disabling network tests
|
105
|
-
|
106
|
-
If the environment variable `NONET` is set to true, then all tests with no cached response available will be marked as pending.
|
107
|
-
|
108
|
-
### http_proxy
|
109
|
-
|
110
|
-
If you need to use a proxy server to access the validator service, set the environment variable http_proxy.
|
111
|
-
|
112
|
-
Configuration
|
113
|
-
-------------
|
114
|
-
|
115
|
-
The following can be set in `spec/support/be_valid_asset.rb`:
|
116
|
-
|
117
|
-
### Display Full source for failures:
|
118
|
-
|
119
|
-
BeValidAsset::Configuration.display_invalid_content = false (default)
|
120
|
-
|
121
|
-
### Display surrounding source for failures:
|
122
|
-
|
123
|
-
This will cause it to output the failing line, and n surrounding lines (defaults to 5)
|
124
|
-
|
125
|
-
BeValidAsset::Configuration.display_invalid_lines = false (default)
|
126
|
-
BeValidAsset::Configuration.display_invalid_lines_count = 5 (default)
|
127
|
-
|
128
|
-
### Change validator host/path:
|
129
|
-
|
130
|
-
BeValidAsset::Configuration.markup_validator_host = 'validator.w3.org'
|
131
|
-
BeValidAsset::Configuration.markup_validator_path = '/check'
|
132
|
-
BeValidAsset::Configuration.css_validator_host = 'jigsaw.w3.org'
|
133
|
-
BeValidAsset::Configuration.css_validator_path = '/css-validator/validator'
|
134
|
-
BeValidAsset::Configuration.feed_validator_host = 'validator.w3.org'
|
135
|
-
BeValidAsset::Configuration.feed_validator_path = '/feed/check.cgi'
|
136
|
-
|
137
|
-
If you are doing more than the occasional check, you should run your own copy of the validator, and use that.
|
138
|
-
Instructions here: [http://validator.w3.org/docs/install.html](http://validator.w3.org/docs/install.html), [http://jigsaw.w3.org/css-validator/DOWNLOAD.html](http://jigsaw.w3.org/css-validator/DOWNLOAD.html) or [http://validator.w3.org/feed/about.html#where](http://validator.w3.org/feed/about.html#where)
|
139
|
-
|
140
|
-
### Caching
|
141
|
-
|
142
|
-
be\_valid\_asset can cache the responses from the validator to save look-ups for documents that haven't changed.
|
143
|
-
To use this feature, it must be enabled, and a cache path must be set:
|
144
|
-
|
145
|
-
BeValidAsset::Configuration.enable_caching = true
|
146
|
-
BeValidAsset::Configuration.cache_path = File.join(RAILS_ROOT, %w(tmp be_valid_asset_cache))
|
147
|
-
|
148
|
-
Issues / Feature Requests
|
149
|
-
-------------------------
|
150
|
-
|
151
|
-
Please use the [github issue tracker](http://github.com/unboxed/be_valid_asset/issues) to track any bugs/feature requests.
|
152
|
-
|
153
|
-
Licensing etc.
|
154
|
-
--------------
|
155
|
-
|
156
|
-
This was originally based on a blog post here: [http://www.anodyne.ca/2007/09/28/rspec-custom-matchers-and-be\_valid\_xhtml/](http://www.anodyne.ca/2007/09/28/rspec-custom-matchers-and-be_valid_xhtml/)
|
157
|
-
|
158
|
-
This is distributed under the MIT Licence, see `MIT-LICENSE.txt` for the details.
|