w3c_rspec_validators 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  *.swp
6
+ *~
data/README.md CHANGED
@@ -32,3 +32,22 @@ end
32
32
 
33
33
  If you want to check html code, that has been modified by javascript, use "page.body.should be_valid_html".
34
34
  Note that a browser may correct wrongly nested tags on its own.
35
+
36
+ ## Running faster offline validation
37
+
38
+ If you do not want to use the online W3C Validation service, which is default, you can set the validator url to a locally runnig version
39
+ of the W3C Validator service by creating a config file:
40
+
41
+ rails g w3c_rspec_validators:config
42
+
43
+ Check this url to see how to install your local version of the W3C validation service: http://validator.w3.org/docs/install.html
44
+ For local HTML5 validation to work you'll need validator.nu running locally too: http://about.validator.nu/
45
+
46
+ ## Licence
47
+ MIT License
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
52
+
53
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ module W3cRspecValidators
2
+ module Generators
3
+ class ConfigGenerator < Rails::Generators::Base
4
+ desc 'Creates a w3c_rspec_validators gem configuration file at config/w3c_rspec_validators.yml'
5
+
6
+ def self.source_root
7
+ @_source_root ||= File.expand_path("../templates", __FILE__)
8
+ end
9
+
10
+ def create_config_file
11
+ template 'w3c_rspec_validators.yml', File.join('config', 'w3c_rspec_validators.yml')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ config:
2
+ w3c_service_uri: "http://localhost.de/check"
@@ -1,20 +1,6 @@
1
- require "w3c_rspec_validators/version"
2
1
  require "w3c_validators"
3
2
 
4
- module W3cRspecValidators
5
- include W3CValidators
6
-
7
- class HTML5Validator
8
- def self.validator_uri
9
- @@validator_uri
10
- end
11
-
12
- def self.validator_uri= value
13
- @@validator_uri = value
14
- end
15
-
16
- self.validator_uri = "http://validator.w3.org/check"
17
- end
18
- end
19
-
3
+ require "w3c_rspec_validators/version"
4
+ require "w3c_rspec_validators/config"
5
+ require "w3c_rspec_validators/validator"
20
6
  require "w3c_rspec_validators/rspec"
@@ -0,0 +1,28 @@
1
+ require "rails"
2
+
3
+ module W3cRspecValidators
4
+
5
+ class Railtie < Rails::Railtie
6
+ initializer "initialize config" do
7
+ config_file = Rails.root.join("config", "w3c_rspec_validators.yml")
8
+ if config_file.file? &&
9
+ Config.load!(config_file)
10
+ end
11
+ end
12
+ end
13
+
14
+ class Config
15
+ @@config = {
16
+ validator_uri: ""
17
+ }
18
+
19
+ def self.load! config_file
20
+ @@config = YAML.load(File.open(config_file))["config"]
21
+ end
22
+
23
+ def self.get
24
+ @@config
25
+ end
26
+ end
27
+
28
+ end
@@ -1,14 +1,13 @@
1
1
  module W3cRspecValidators
2
2
 
3
3
  RSpec::Matchers.define :be_valid_html do
4
- response = nil
4
+ validator = Validator.new
5
5
  match do |body|
6
- validator = MarkupValidator.new :validator_uri => HTML5Validator.validator_uri
7
- response = validator.validate_text(body)
8
- response.errors.length == 0
6
+ validator.validate_text(body)
7
+ validator.response.errors.length == 0
9
8
  end
10
9
  failure_message_for_should do |actual|
11
- response.errors.map do |err|
10
+ validator.response.errors.map do |err|
12
11
  seperator = "######\n"
13
12
  error = /line \d.*/.match err.to_s
14
13
  line_number = /line (\d*)/.match(err.to_s)[1].to_i
@@ -0,0 +1,15 @@
1
+ module W3cRspecValidators
2
+ class Validator
3
+ attr_reader :response
4
+ include W3CValidators
5
+
6
+ def initialize
7
+ @validator = MarkupValidator.new validator_uri: Config.get["w3c_service_uri"]
8
+ end
9
+
10
+ def validate_text text
11
+ @response = @validator.validate_text(text)
12
+ raise "Error: Invalid validation response! Tip: check if validator.nu engine is configured correctly" if @response.checked_by.blank?
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module W3cRspecValidators
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -56,7 +56,8 @@ describe "be_valid_html" do
56
56
  end
57
57
 
58
58
  it "should use a custom uri if provided" do
59
- W3cRspecValidators::HTML5Validator.validator_uri = "http://blubb.de"
59
+ W3cRspecValidators::Config.stub(:get).and_return("w3c_service_uri" => "http://blubb.de")
60
+
60
61
  validator = MarkupValidator.new
61
62
  MarkupValidator.should_receive(:new).with(:validator_uri => "http://blubb.de").and_return validator
62
63
 
@@ -0,0 +1,29 @@
1
+ require "w3c_rspec_validators"
2
+ include W3CValidators
3
+
4
+ describe W3cRspecValidators::Validator do
5
+
6
+ describe "initialize" do
7
+ it "should initialize MarkupValidator with config value" do
8
+ W3cRspecValidators::Config.stub(:get).and_return("w3c_service_uri" => "http://blubb.de")
9
+ MarkupValidator.should_receive(:new).with(validator_uri: "http://blubb.de")
10
+
11
+ W3cRspecValidators::Validator.new
12
+ end
13
+ end
14
+
15
+ describe "validate_text" do
16
+ it "should raise an exception if validation fails silently" do
17
+ class Dummy
18
+ def checked_by
19
+ ""
20
+ end
21
+ end
22
+ MarkupValidator.any_instance.stub(:validate_text).and_return Dummy.new
23
+
24
+ expect {
25
+ W3cRspecValidators::Validator.new.validate_text("dummy")
26
+ }.to raise_exception
27
+ end
28
+ end
29
+ end
@@ -21,4 +21,6 @@ Gem::Specification.new do |s|
21
21
  # specify any dependencies here; for example:
22
22
  # s.add_development_dependency "rspec"
23
23
  s.add_runtime_dependency "w3c_validators"
24
+ s.add_runtime_dependency "rspec"
25
+ s.add_runtime_dependency "rails"
24
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: w3c_rspec_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-17 00:00:00.000000000 Z
12
+ date: 2012-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: w3c_validators
16
- requirement: &13322940 !ruby/object:Gem::Requirement
16
+ requirement: &13643700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,29 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13322940
24
+ version_requirements: *13643700
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &13641700 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *13641700
36
+ - !ruby/object:Gem::Dependency
37
+ name: rails
38
+ requirement: &13639620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *13639620
25
47
  description: At this time it allows for validation of html (including html5) produced
26
48
  by rspec acceptance tests. In addition you can configure the gem to use a locally
27
49
  installed validation service instead of the online w3c servers
@@ -35,10 +57,15 @@ files:
35
57
  - Gemfile
36
58
  - README.md
37
59
  - Rakefile
60
+ - lib/rails/generators/w3c_rspec_validators/config/config_generator.rb
61
+ - lib/rails/generators/w3c_rspec_validators/config/templates/w3c_rspec_validators.yml
38
62
  - lib/w3c_rspec_validators.rb
63
+ - lib/w3c_rspec_validators/config.rb
39
64
  - lib/w3c_rspec_validators/rspec.rb
65
+ - lib/w3c_rspec_validators/validator.rb
40
66
  - lib/w3c_rspec_validators/version.rb
41
67
  - spec/matchers_spec.rb
68
+ - spec/validator_spec.rb
42
69
  - w3c_rspec_validators.gemspec
43
70
  homepage: ''
44
71
  licenses: []