monet 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+ require 'monet/page_logger'
3
+
4
+ describe Monet::PageLogger do
5
+ When { log.add("http://google.com", 200) }
6
+ When { log.add("http://google.com/chrome", 302) }
7
+ When { log.add("http://google.com/notathing", 404) }
8
+ When { log.add("http://lance.com/snack", 403) }
9
+
10
+ shared_examples "valid logger" do
11
+ context "logs a set of responses for urls" do
12
+ Then { log.failures.size.should == 2 }
13
+ And { log.successes.size.should == 2 }
14
+ And { log.failures.should == {"http://google.com/notathing" => 404, "http://lance.com/snack" => 403} }
15
+ end
16
+
17
+ context "can lookup a url's status" do
18
+ When(:result) { log.status_for("http://google.com/chrome") }
19
+ Then { result.should == 302 }
20
+ end
21
+
22
+ context "can test for failure of a failed url" do
23
+ When(:result) { log.failed?("http://google.com/notathing") }
24
+ Then { result.should be_true }
25
+ end
26
+
27
+ context "can test for failure of a successful url" do
28
+ When(:result) { log.failed?("http://google.com/chrome") }
29
+ Then { result.should be_false }
30
+ end
31
+
32
+ context "can test for success of a bad url" do
33
+ When(:result) { log.succeeded?("http://google.com/notathing") }
34
+ Then { result.should be_false }
35
+ end
36
+
37
+ context "can test for success of a good url" do
38
+ When(:result) { log.succeeded?("http://google.com") }
39
+ Then { result.should be_true }
40
+ end
41
+
42
+ context "raises no UnseenUrl error for url that hasn't been seen" do
43
+ Given(:url) { "http://www.spider.io" }
44
+ When(:result) { log.status_for(url) }
45
+ Then { result.should have_failed(Monet::Errors::UnseenURL, "There is no recorded status for #{url}") }
46
+ end
47
+
48
+ context "can count records" do
49
+ Then { log.size.should == 4 }
50
+ end
51
+
52
+ context "can reference like an array" do
53
+ Then { log["http://google.com"].should == 200 }
54
+ And { log["http://google.com/notathing"].should == 404 }
55
+ end
56
+
57
+ context "cannot set method on log directly" do
58
+ When(:result) { log["test.com"] = 209 }
59
+ Then { result.should have_failed }
60
+ end
61
+ end
62
+
63
+ context "initialized logger" do
64
+ it_should_behave_like "valid logger" do
65
+ Given(:log) { Monet::PageLogger.instance }
66
+ end
67
+ end
68
+
69
+ context "log persistance" do
70
+ Given(:log) { Monet::PageLogger.instance }
71
+ Given(:path) { "./spec/tmp/output/log.txt" }
72
+ When { log.save(path) }
73
+
74
+ context "can save a log file" do
75
+ Then { File.exists?(path).should be_true }
76
+ end
77
+
78
+ context "has a csv listing of urls and codes" do
79
+ When(:txt) { IO.readlines(path) }
80
+ Then { txt.should == %W(http://google.com,200\n http://google.com/chrome,302\n http://google.com/notathing,404\n http://lance.com/snack,403\n) }
81
+ end
82
+
83
+ context "can load a listing of codes from file" do
84
+ it_should_behave_like "valid logger" do
85
+ Given(:log) { Monet::PageLogger.load(path) }
86
+ end
87
+ end
88
+ end
89
+ end
@@ -4,6 +4,7 @@ require 'timecop'
4
4
  require 'pry'
5
5
 
6
6
  require 'monet/config'
7
+ require 'monet/page_logger'
7
8
 
8
9
  VCR.configure do |c|
9
10
  c.cassette_library_dir = 'spec/cassettes'
@@ -14,4 +15,7 @@ end
14
15
  RSpec.configure do |c|
15
16
  c.mock_with :flexmock
16
17
  c.treat_symbols_as_metadata_keys_with_true_values = true
18
+ c.before(:all) do
19
+ Monet::PageLogger.reset
20
+ end
17
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke van der Hoeven
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
11
+ date: 2014-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -147,8 +147,10 @@ files:
147
147
  - lib/monet/compare.rb
148
148
  - lib/monet/config.rb
149
149
  - lib/monet/diff_strategy.rb
150
+ - lib/monet/error_image.rb
150
151
  - lib/monet/errors.rb
151
152
  - lib/monet/image.rb
153
+ - lib/monet/page_logger.rb
152
154
  - lib/monet/router.rb
153
155
  - lib/monet/tasks.rb
154
156
  - lib/monet/url_helpers.rb
@@ -174,6 +176,7 @@ files:
174
176
  - spec/fixtures/thumbnails/lance.com/.DS_Store
175
177
  - spec/fixtures/thumbnails/lance.com/lance.com-1024.png
176
178
  - spec/image_spec.rb
179
+ - spec/page_logger_spec.rb
177
180
  - spec/router_spec.rb
178
181
  - spec/spec_helper.rb
179
182
  - spec/tmp/test.png
@@ -224,6 +227,7 @@ test_files:
224
227
  - spec/fixtures/thumbnails/lance.com/.DS_Store
225
228
  - spec/fixtures/thumbnails/lance.com/lance.com-1024.png
226
229
  - spec/image_spec.rb
230
+ - spec/page_logger_spec.rb
227
231
  - spec/router_spec.rb
228
232
  - spec/spec_helper.rb
229
233
  - spec/tmp/test.png