site_watcher 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/site_watcher.rb +70 -28
- data/lib/site_watcher/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5767baf72233d2af5eec6adb9b2810e0b8e8bd6c
|
4
|
+
data.tar.gz: 77bfeb19efc58a3d42e993bef52ce38f9e8087a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2491e2466343d145acf42246243612d336392fd3850138e10135b183418a23ec9e8e5245be49ed259311808484dbdf675fe79bf80820c36f08cdcc5eb21d8d0
|
7
|
+
data.tar.gz: 282ee975b7b81731b4e06e3e42f7e3b10435a360d3181c92ea5ead7cf2859cb8a2d3dc3775dfa478a5186357ed9f44bc95ca7b827fd01e5e1a77219463352827
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# SiteWatcher
|
1
|
+
# SiteWatcher [![Gem Version](https://badge.fury.io/rb/site_watcher.svg)](http://badge.fury.io/rb/site_watcher)
|
2
2
|
|
3
3
|
I wrote this to notify me when the Wii U Gamecube controller adapter becomes
|
4
4
|
available.
|
@@ -46,6 +46,10 @@ end
|
|
46
46
|
|
47
47
|
This script will block until all expectations have been fulfilled.
|
48
48
|
|
49
|
+
## Testing fulfillment
|
50
|
+
|
51
|
+
You can force a `SiteWatcher.watch` process to run each of its `fulfilled` blocks by sending it the `USR1` signal. The process will continue to run as normal after each block has been called.
|
52
|
+
|
49
53
|
## Contributing
|
50
54
|
|
51
55
|
1. Fork it ( https://github.com/[my-github-username]/site_watcher/fork )
|
data/lib/site_watcher.rb
CHANGED
@@ -10,67 +10,97 @@ class SiteWatcher
|
|
10
10
|
def self.watch(opts={}, &block)
|
11
11
|
trap(:SIGINT) { abort(?\n) }
|
12
12
|
|
13
|
-
delay = opts.fetch(:every, 5)
|
14
13
|
dsl = DSL::Top.new
|
15
14
|
dsl.instance_eval(&block)
|
16
15
|
|
17
|
-
|
16
|
+
delay = opts.fetch(:every, 5)
|
17
|
+
logger = opts.fetch(:logger, ::Logger.new($stderr))
|
18
|
+
new(dsl.__sw_pages, delay, logger).watch
|
18
19
|
end
|
19
20
|
|
20
|
-
def initialize(pages)
|
21
|
+
def initialize(pages, delay, logger)
|
21
22
|
@pages = pages
|
22
|
-
@
|
23
|
+
@delay = delay
|
24
|
+
@logger = logger
|
25
|
+
@force = false
|
23
26
|
end
|
24
27
|
|
25
|
-
def watch
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def watch
|
29
|
+
capture_signals do
|
30
|
+
loop do
|
31
|
+
break if @pages.empty?
|
32
|
+
|
33
|
+
force = @force
|
34
|
+
@force &&= false
|
35
|
+
|
36
|
+
@pages.each do |page|
|
37
|
+
begin
|
38
|
+
page.__sw_run!(force)
|
39
|
+
@pages.delete(page)
|
40
|
+
rescue ::RSpec::Expectations::ExpectationNotMetError
|
41
|
+
rescue => e
|
42
|
+
@logger.warn("Exception on #{page.__sw_url}: #{e.inspect}")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
sleep(@delay)
|
33
47
|
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def capture_signals
|
54
|
+
::Signal.trap(:INT) { abort(?\n) }
|
34
55
|
|
35
|
-
|
56
|
+
::Signal.trap(:USR1) do
|
57
|
+
::Thread.new do
|
58
|
+
@logger.warn("Received USR1, next round of tests will force fulfillment")
|
59
|
+
end.join
|
60
|
+
|
61
|
+
@force = true
|
36
62
|
end
|
63
|
+
|
64
|
+
yield
|
65
|
+
ensure
|
66
|
+
::Signal.trap(:INT, "DEFAULT")
|
67
|
+
::Signal.trap(:USR1, "DEFAULT")
|
37
68
|
end
|
38
69
|
|
39
70
|
module DSL
|
40
71
|
class Top
|
41
|
-
attr_reader :
|
72
|
+
attr_reader :__sw_pages
|
42
73
|
|
43
74
|
def initialize
|
44
|
-
@
|
75
|
+
@__sw_pages = []
|
45
76
|
end
|
46
77
|
|
47
78
|
def page(url, &block)
|
48
|
-
Page.new(url)
|
49
|
-
|
50
|
-
|
51
|
-
end
|
79
|
+
page = Page.new(url)
|
80
|
+
page.instance_eval(&block)
|
81
|
+
@__sw_pages << page
|
52
82
|
end
|
53
83
|
end
|
54
84
|
|
55
85
|
class Page
|
56
86
|
include ::RSpec::Matchers
|
57
|
-
attr_reader :
|
87
|
+
attr_reader :__sw_url
|
58
88
|
|
59
89
|
def initialize(url)
|
60
|
-
@
|
61
|
-
@
|
90
|
+
@__sw_url = url
|
91
|
+
@__sw_tests = []
|
62
92
|
end
|
63
93
|
|
64
94
|
def test(&block)
|
65
|
-
@
|
95
|
+
@__sw_tests << block
|
66
96
|
end
|
67
97
|
|
68
98
|
def fulfilled(&block)
|
69
|
-
@
|
99
|
+
@__sw_fulfilled = block
|
70
100
|
end
|
71
101
|
|
72
|
-
def
|
73
|
-
|
102
|
+
def __sw_run!(force=false)
|
103
|
+
::OpenURI.open_uri(@__sw_url) do |response|
|
74
104
|
case response.content_type
|
75
105
|
when /json/i
|
76
106
|
page = ::JSON.parse(response.read)
|
@@ -78,10 +108,22 @@ class SiteWatcher
|
|
78
108
|
page = ::Capybara::Node::Simple.new(response.read)
|
79
109
|
end
|
80
110
|
|
81
|
-
|
82
|
-
|
111
|
+
begin
|
112
|
+
@__sw_tests.each { |test| test.call(page) }
|
113
|
+
rescue ::RSpec::Expectations::ExpectationNotMetError => err
|
114
|
+
__sw_fulfilled! if force
|
115
|
+
raise(err)
|
116
|
+
end
|
117
|
+
|
118
|
+
__sw_fulfilled!
|
83
119
|
end
|
84
120
|
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def __sw_fulfilled!
|
125
|
+
@__sw_fulfilled.call(@__sw_url) if @__sw_fulfilled.respond_to?(:call)
|
126
|
+
end
|
85
127
|
end
|
86
128
|
end
|
87
129
|
end
|
data/lib/site_watcher/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_watcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Genco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|