rspec-sitemap-matchers 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -44,10 +44,13 @@ These matchers can be used on `File`s, `String`s and any arbitary `IO` instance
44
44
  The matchers also support more specific attribution matching, such as priorities as per the Sitemap protocol. These can be chained together:
45
45
 
46
46
  it { should include_url('http://www.example.com').priority(0.5) }
47
+ it { should include_url('http://www.example.com').changefreq('weekly') }
48
+ it { should include_url('http://www.example.com').lastmod('2012-07-16T19:20+01:00') }
49
+
50
+ Note: You can chanin multiple attribute matchers together, like `.lastod('…').changefreq('…')` etc.
47
51
 
48
52
  ## Planned features
49
53
 
50
- * More chainable attribute modifiers, such as `lastmod` and `changefreq`
51
54
  * Stricter markup and structure validation
52
55
  * Encoding validation matcher (Sitemaps must be UTF-8 encoded)
53
56
  * `be_a_valid_sitemap` matcher
@@ -64,4 +67,4 @@ The matchers also support more specific attribution matching, such as priorities
64
67
 
65
68
  ## Copyright
66
69
 
67
- Copyright © 2012 Attila Györffy and [Unboxed Consulting](http://www.unboxedconsulting.com). See LICENSE for details.
70
+ Copyright © 2012 Attila Györffy, [Unboxed Consulting](http://www.unboxedconsulting.com) and [contributors](http://github.com/unboxed/rspec-sitemap-matchers/graphs/contributors). See LICENSE for details.
@@ -1,5 +1,8 @@
1
1
  module RSpec::Sitemap::Matchers
2
2
  class IncludeUrl
3
+
4
+ ALLOWED_ATTRS = %w(priority changefreq lastmod)
5
+
3
6
  def initialize(expected_location)
4
7
  @expected_location = expected_location
5
8
  end
@@ -29,7 +32,21 @@ module RSpec::Sitemap::Matchers
29
32
  self
30
33
  end
31
34
 
32
- private
35
+ def lastmod(expected_lastmod)
36
+ expected_attributes.merge!(:lastmod => expected_lastmod)
37
+ self
38
+ end
39
+
40
+ def changefreq(expected_changefreq)
41
+ expected_attributes.merge!(:changefreq => expected_changefreq)
42
+ self
43
+ end
44
+
45
+ ALLOWED_ATTRS.each do |attr|
46
+ alias_method "with_#{attr}".to_sym, attr.to_sym
47
+ end
48
+
49
+ private
33
50
 
34
51
  def expected_attributes
35
52
  @expected_attributes ||= {}
@@ -43,8 +60,8 @@ module RSpec::Sitemap::Matchers
43
60
 
44
61
  def matched_attributes
45
62
  attributes = {}
46
- matched_node.children.each do |node|
47
- attributes[node.name.to_sym] = node.text
63
+ unless matched_node.nil?
64
+ matched_node.children.each { |node| attributes[node.name.to_sym] = node.text }
48
65
  end
49
66
  attributes
50
67
  end
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Sitemap
3
3
  module Matchers
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
@@ -6,20 +6,6 @@ module RSpec::Sitemap::Matchers
6
6
 
7
7
  describe "#matches?" do
8
8
 
9
- shared_examples_for "a matcher that passes or fails" do
10
- it "passes" do
11
- sitemap.should include_url('http://www.example.com')
12
- end
13
-
14
- it "fails" do
15
- expect {
16
- sitemap.should include_url('http://www.not-an-example.com')
17
- }.to raise_error { |error|
18
- error.message.should match("to include a URL to http://www.not-an-example.com")
19
- }
20
- end
21
- end
22
-
23
9
  context "on a File" do
24
10
  it_should_behave_like "a matcher that passes or fails" do
25
11
  let(:sitemap) { fixture('basic') }
@@ -43,32 +29,43 @@ module RSpec::Sitemap::Matchers
43
29
  end
44
30
  end
45
31
 
32
+ describe "#failure_message" do
33
+
34
+ let(:sitemap) { fixture('basic').read }
35
+
36
+ it "should not raise error when attributes are queried on missing url" do
37
+ expect {
38
+ # not included url
39
+ sitemap.should include_url('http://www.example.org').priority(0.5)
40
+ }.to_not raise_error NoMethodError
41
+ end
42
+ end
43
+
46
44
  describe "#priority" do
47
- context "when it is set" do
48
- let(:sitemap) { fixture('with_valid_priority') }
49
- it "passes" do
50
- sitemap.should include_url('http://www.example.com').priority('0.5')
51
- end
52
45
 
53
- it "fails" do
54
- expect {
55
- sitemap.should include_url('http://www.example.com').priority('0.8')
56
- }.to raise_error { |error|
57
- error.message.should match('to include a URL to http://www.example.com with a priority of 0.8 but it was set to 0.5')
58
- }
59
- end
46
+ it_should_behave_like "an attribute matcher", "priority", 0.5, 0.8 do
47
+ let(:passing_sitemap) { fixture('with_valid_priority') }
48
+ let(:failing_sitemap) { fixture('basic') }
60
49
  end
61
50
 
62
- context "when it is NOT set" do
63
- let(:sitemap) { fixture('basic') }
64
- it "fails" do
65
- expect {
66
- sitemap.should include_url('http://www.example.com').priority('0.5')
67
- }.to raise_error { |error|
68
- error.message.should match('to include a URL to http://www.example.com with a priority of 0.5 but the priority was not set')
69
- }
70
- end
51
+ end
52
+
53
+ describe "#changefreq" do
54
+
55
+ it_should_behave_like "an attribute matcher", "changefreq", "weekly", "daily" do
56
+ let(:passing_sitemap) { fixture('with_valid_priority') }
57
+ let(:failing_sitemap) { fixture('basic') }
71
58
  end
59
+
60
+ end
61
+
62
+ describe "#lastmod" do
63
+
64
+ it_should_behave_like "an attribute matcher", "lastmod", "2012-11-27T16:40:53+01:00", "not prova" do
65
+ let(:passing_sitemap) { fixture('with_valid_priority') }
66
+ let(:failing_sitemap) { fixture('basic') }
67
+ end
68
+
72
69
  end
73
70
  end
74
71
  end
@@ -7,6 +7,7 @@
7
7
 
8
8
  require 'rspec/sitemap/matchers'
9
9
  require 'support/fixture_helper'
10
+ require 'support/shared_examples'
10
11
 
11
12
  RSpec.configure do |config|
12
13
  config.treat_symbols_as_metadata_keys_with_true_values = true
@@ -3,5 +3,7 @@
3
3
  <url>
4
4
  <loc>http://www.example.com</loc>
5
5
  <priority>0.5</priority>
6
+ <lastmod>2012-11-27T16:40:53+01:00</lastmod>
7
+ <changefreq>weekly</changefreq>
6
8
  </url>
7
9
  </urlset>
@@ -0,0 +1,47 @@
1
+ shared_examples_for "a matcher that passes or fails" do
2
+ it "passes" do
3
+ sitemap.should include_url('http://www.example.com')
4
+ end
5
+
6
+ it "fails" do
7
+ expect {
8
+ sitemap.should include_url('http://www.not-an-example.com')
9
+ }.to raise_error { |error|
10
+ error.message.should match("to include a URL to http://www.not-an-example.com")
11
+ }
12
+ end
13
+ end
14
+
15
+ shared_examples_for "an attribute matcher" do |attribute, expected, not_expected|
16
+
17
+ context "when #{attribute} is set" do
18
+
19
+ it "passes" do
20
+ passing_sitemap.should include_url('http://www.example.com').send(attribute, expected)
21
+ end
22
+
23
+ it "passes when invoked with with_ syntax" do
24
+ passing_sitemap.should include_url('http://www.example.com').send("with_#{attribute}", expected)
25
+ end
26
+
27
+ it "fails" do
28
+ expect {
29
+ passing_sitemap.should include_url('http://www.example.com').send(attribute, not_expected)
30
+ }.to raise_error { |error|
31
+ error.message.should include("to include a URL to http://www.example.com with a #{attribute} of #{not_expected} but it was set to #{expected}")
32
+ }
33
+ end
34
+ end
35
+
36
+ context "when #{attribute} is NOT set" do
37
+
38
+ it "fails" do
39
+ expect {
40
+ failing_sitemap.should include_url('http://www.example.com').send(attribute, expected)
41
+ }.to raise_error { |error|
42
+ error.message.should include("to include a URL to http://www.example.com with a #{attribute} of #{expected} but the #{attribute} was not set")
43
+ }
44
+ end
45
+ end
46
+
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-sitemap-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-03 00:00:00.000000000 Z
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -81,6 +81,7 @@ files:
81
81
  - spec/support/fixture_helper.rb
82
82
  - spec/support/fixtures/sitemaps/basic.xml
83
83
  - spec/support/fixtures/sitemaps/with_valid_priority.xml
84
+ - spec/support/shared_examples.rb
84
85
  homepage: http://github.com/unboxed/rspec-sitemap-matchers
85
86
  licenses: []
86
87
  post_install_message:
@@ -95,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
96
  version: '0'
96
97
  segments:
97
98
  - 0
98
- hash: -4581193510046784126
99
+ hash: 292912089253574170
99
100
  required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  none: false
101
102
  requirements:
@@ -104,10 +105,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  version: '0'
105
106
  segments:
106
107
  - 0
107
- hash: -4581193510046784126
108
+ hash: 292912089253574170
108
109
  requirements: []
109
110
  rubyforge_project:
110
- rubygems_version: 1.8.24
111
+ rubygems_version: 1.8.23
111
112
  signing_key:
112
113
  specification_version: 3
113
114
  summary: Sitemap protocol matchers for RSpec
@@ -117,3 +118,4 @@ test_files:
117
118
  - spec/support/fixture_helper.rb
118
119
  - spec/support/fixtures/sitemaps/basic.xml
119
120
  - spec/support/fixtures/sitemaps/with_valid_priority.xml
121
+ - spec/support/shared_examples.rb