smoke 0.0.3 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +101 -0
- data/Rakefile +53 -4
- data/VERSION.yml +4 -0
- data/examples/web_search_joined.rb +25 -0
- data/examples/yql_web_search.rb +11 -0
- data/lib/core_ext/hash.rb +20 -0
- data/lib/core_ext/string.rb +6 -0
- data/lib/smoke.rb +103 -3
- data/lib/smoke/cache.rb +56 -0
- data/lib/smoke/origin.rb +251 -0
- data/lib/smoke/request.rb +57 -0
- data/lib/smoke/source/data.rb +39 -0
- data/lib/smoke/source/feed.rb +24 -0
- data/lib/smoke/source/join.rb +33 -0
- data/lib/smoke/source/yql.rb +85 -0
- data/rdoc/classes/Smoke.html +260 -0
- data/rdoc/classes/Smoke/Origin.html +340 -0
- data/rdoc/classes/Smoke/Source/Data.html +126 -0
- data/rdoc/classes/Smoke/Source/Feed.html +117 -0
- data/rdoc/classes/Smoke/Source/YQL.html +223 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/README_markdown.html +180 -0
- data/rdoc/files/lib/core_ext/hash_rb.html +49 -0
- data/rdoc/files/lib/smoke/origin_rb.html +49 -0
- data/rdoc/files/lib/smoke/request_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/data_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/feed_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/join_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/yql_rb.html +49 -0
- data/rdoc/files/lib/smoke_rb.html +65 -0
- data/rdoc/fr_class_index.html +21 -0
- data/rdoc/fr_file_index.html +28 -0
- data/rdoc/fr_method_index.html +4459 -0
- data/rdoc/index.html +15 -0
- data/rdoc/rdoc-style.css +319 -0
- data/spec/core_ext/hash_spec.rb +25 -0
- data/spec/smoke/cache_spec.rb +75 -0
- data/spec/smoke/origin_spec.rb +220 -0
- data/spec/smoke/request_spec.rb +49 -0
- data/spec/smoke/shared_spec.rb +182 -0
- data/spec/smoke/source/data_spec.rb +65 -0
- data/spec/smoke/source/feed_spec.rb +49 -0
- data/spec/smoke/source/join_spec.rb +53 -0
- data/spec/smoke/source/yql_spec.rb +111 -0
- data/spec/smoke_spec.rb +51 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/supports/amc_pacer.json.yql +10 -0
- data/spec/supports/datatables.yql +12 -0
- data/spec/supports/flickr-photo.json +7 -0
- data/spec/supports/gzip_response.txt +0 -0
- data/spec/supports/search-web.json.yql +12 -0
- data/spec/supports/search-web.xml.yql +83 -0
- data/spec/supports/slashdot.xml +98 -0
- data/spec/supports/test_source.rb +10 -0
- metadata +144 -67
- data/History.txt +0 -13
- data/License.txt +0 -21
- data/Manifest.txt +0 -44
- data/README.txt +0 -3
- data/bin/smoke +0 -41
- data/bin/smoked +0 -43
- data/config/hoe.rb +0 -70
- data/config/requirements.rb +0 -17
- data/contrib/processors/smoke/remote_port_status_check_processor.rb +0 -10
- data/contrib/processors/smoke/system_load_processor.rb +0 -52
- data/contrib/signals/smoke/remote_port_status_check.rb +0 -39
- data/contrib/signals/smoke/system_load.rb +0 -23
- data/lib/smoke/client.rb +0 -50
- data/lib/smoke/client/connection.rb +0 -44
- data/lib/smoke/client/signal_runner.rb +0 -40
- data/lib/smoke/client/version.rb +0 -11
- data/lib/smoke/server.rb +0 -18
- data/lib/smoke/server/signal_handler.rb +0 -64
- data/lib/smoke/server/signal_router.rb +0 -38
- data/lib/smoke/server/version.rb +0 -11
- data/lib/smoke/signal.rb +0 -19
- data/lib/smoke/signal_processor.rb +0 -29
- data/lib/smoke/version.rb +0 -9
- data/log/debug.log +0 -0
- data/log/development.log +0 -0
- data/log/production.log +0 -0
- data/log/server.log +0 -0
- data/log/test.log +0 -0
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -74
- data/setup.rb +0 -1585
- data/tasks/deployment.rake +0 -35
- data/tasks/environment.rake +0 -7
- data/tasks/website.rake +0 -17
- data/test/test_helper.rb +0 -2
- data/test/test_server.rb +0 -11
- data/website/index.html +0 -87
- data/website/index.txt +0 -29
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -138
- data/website/template.rhtml +0 -48
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper.rb")
|
2
|
+
|
3
|
+
describe Smoke::Request do
|
4
|
+
before do
|
5
|
+
@url = "http://fake.tld/canned/"
|
6
|
+
@web_search = File.join(SPEC_DIR, 'supports', 'flickr-photo.json')
|
7
|
+
FakeWeb.register_uri(@url, :response => @web_search)
|
8
|
+
@request = Smoke::Request.new(@url)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return a Request object" do
|
12
|
+
@request.should be_an_instance_of(Smoke::Request)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have a content type" do
|
16
|
+
@request.content_type.should == "text/plain; charset=utf-8"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be a raw string response" do
|
20
|
+
request = Smoke::Request.new(@url, :raw_response => true)
|
21
|
+
request.body.should == "{\"photos\":{\"page\":1, \"pages\":1, \"perpage\":100, \"total\":\"2\", \"photo\":[{\"id\":\"3443335843\", \"owner\":\"36821533@N00\", \"secret\":\"5a15f0bfb9\", \"server\":\"3305\", \"farm\":4, \"title\":\"How I roll\", \"ispublic\":1, \"isfriend\":0, \"isfamily\":0}, {\"id\":\"3345220961\", \"owner\":\"36821533@N00\", \"secret\":\"a1dd2b9eca\", \"server\":\"3581\", \"farm\":4, \"title\":\"My desk\", \"ispublic\":1, \"isfriend\":0, \"isfamily\":0}]}, \"stat\":\"ok\"}"
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "gzipped responses" do
|
25
|
+
before do
|
26
|
+
# Gzip response should come out exactly the same as the plain text response
|
27
|
+
@gzip_response = File.join(SPEC_DIR, 'supports', 'gzip_response.txt')
|
28
|
+
@url = "http://fake.tld/gzip"
|
29
|
+
FakeWeb.register_uri(@url, :response => @gzip_response, :content_encoding => "gzip")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should transparently handle a gzipped response" do
|
33
|
+
request = Smoke::Request.new(@url)
|
34
|
+
request.body.should == "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n\t\"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n\t<head>\n\t\t<title>New street represent</title>\n\t\t<style type=\"text/css\" media=\"screen\">\n\t\t\tbody {\n\t\t\t\tfont-family: helvetica, arial, sans-serif;\n\t\t\t\tfont-size: 2em;\n\t\t\t\tbackground-color: black;\n\t\t\t\tletter-spacing: -3px;\n\t\t\t\tmargin: 0 auto;\n\t\t\t}\n\t\t\th1 {\n\t\t\t\tposition: absolute;\n\t\t\t\tright: 0;\n\t\t\t\tbackground-color: #666;\n\t\t\t\twidth: 4em;\n\t\t\t}\n\t\t</style>\n\t</head>\n\t<body>\n\t\t<h1>Massive</h1>\n\t</body>\n</html>"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "format returns" do
|
39
|
+
it "should have a content type of :manual" do
|
40
|
+
request = Smoke::Request.new(@url, :type => :manual)
|
41
|
+
request.type.should == :manual
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have a content type of unknown" do
|
45
|
+
request = Smoke::Request.new(@url)
|
46
|
+
request.type.should == :unknown
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper.rb")
|
2
|
+
|
3
|
+
shared_examples_for "all sources" do
|
4
|
+
describe "transforms" do
|
5
|
+
|
6
|
+
it "emit should require a block" do
|
7
|
+
lambda { @source.emit }.should raise_error
|
8
|
+
lambda { @source.emit {} }.should_not raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should respond to transform" do
|
12
|
+
@source.should respond_to(:transform)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "transform should require a block" do
|
16
|
+
lambda { @source.transform }.should raise_error
|
17
|
+
lambda { @source.transform {} }.should_not raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have at least one transformation" do
|
21
|
+
@source.transformation.size.should_not be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "key insertion" do
|
26
|
+
it "should respond to insert" do
|
27
|
+
@source.should respond_to(:insert)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should insert values into each key" do
|
31
|
+
@source.insert(:source, "twitter").output.first.should have_key :source
|
32
|
+
@source.insert(:source, "twitter").output.first[:source].should == "twitter"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "general object transformations" do
|
37
|
+
it "should respond to emit" do
|
38
|
+
@source.should respond_to(:emit)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should rename properties" do
|
42
|
+
@source.rename(:title => :header).output.first.should have_key(:header)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should sort by a given property" do
|
46
|
+
@source.sort(:header).output.first[:header].should == "Kangaroo"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should reverse the results" do
|
50
|
+
@source.sort(:header).reverse.output.should == [{:header => "Platypus", :name => "Peter"}, {:header => "Kangaroo", :name => "Kelly"}]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should truncate results given a length" do
|
54
|
+
@source.truncate(1).output.should be_an_instance_of(Hash)
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "filtering" do
|
58
|
+
before do
|
59
|
+
TestSource.source(:keep) do
|
60
|
+
emit do
|
61
|
+
transform :head do |head|
|
62
|
+
head.gsub(/Animal: /, '')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
TestSource.source(:discard) do
|
68
|
+
emit do
|
69
|
+
transform :head do |head|
|
70
|
+
head.gsub(/Animal: /, '')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should keep items" do
|
77
|
+
@source.should(respond_to(:keep))
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should only contain items that match" do
|
81
|
+
@source.keep(:head, /^K/).output.should == {:head => "Kangaroo", :name => "Kelly"}
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should discard items" do
|
85
|
+
@source.should(respond_to(:discard))
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should not contain items that match" do
|
89
|
+
@source.discard(:head, /^K/).output.should == {:head => "Platypus", :name => "Peter"}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "output" do
|
95
|
+
it "should output" do
|
96
|
+
@source.output.should be_an_instance_of(Array)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should output a single hash when there is only one result" do
|
100
|
+
@source.truncate(1).output.should be_an_instance_of(Hash)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should output two items" do
|
104
|
+
@source.output.size.should == 2
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should output json" do
|
108
|
+
@source.output(:json).should =~ /^\[\{/
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should output yml" do
|
112
|
+
@source.output(:yaml).should =~ /^--- \n- :/
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should dispatch when output is called" do
|
116
|
+
TestSource.source(:dispatch)
|
117
|
+
@source.should_receive(:dispatch)
|
118
|
+
@source.output
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "preperation" do
|
123
|
+
before :all do
|
124
|
+
@source = TestSource.source(:preperation)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should respond to prepare" do
|
128
|
+
@source.should respond_to(:prepare)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should require a block" do
|
132
|
+
lambda { @source.prepare }.should raise_error
|
133
|
+
lambda { @source.prepare {} }.should_not raise_error
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "call order" do
|
138
|
+
before :all do
|
139
|
+
@url = "http://domain.tld/benschwarz/feed"
|
140
|
+
FakeWeb.register_uri(@url, :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
|
141
|
+
|
142
|
+
Smoke.data :feed_preperation_call_order do
|
143
|
+
prepare do
|
144
|
+
url "http://domain.tld/#{username}/feed"
|
145
|
+
end
|
146
|
+
|
147
|
+
path :photos, :photo
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "before setting variables" do
|
152
|
+
it "should fail" do
|
153
|
+
lambda { @source.output }.should raise_error(NameError)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "setting abstract properties" do
|
158
|
+
it "should not respond to a property that hasn't been set" do
|
159
|
+
lambda { @source.abstract }.should raise_error(NoMethodError)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should allow setting a property" do
|
163
|
+
lambda { @source.abstract(:value) }.should_not raise_error(NoMethodError)
|
164
|
+
@source.abstract.should == :value
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should chain the source when setting a property" do
|
168
|
+
@source.abstract(:value).should be_an_instance_of(Smoke::Source::Data)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "after setting variables" do
|
173
|
+
it "should output successfully" do
|
174
|
+
lambda { @source.username("benschwarz").output }.should_not raise_error
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should have used the correct url" do
|
178
|
+
@source.request.uri.should == @url
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
|
2
|
+
|
3
|
+
describe "'Data' source" do
|
4
|
+
before :all do
|
5
|
+
FakeWeb.register_uri("http://photos.tld/index.json", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
|
6
|
+
|
7
|
+
@source = Smoke.data(:photos) do
|
8
|
+
url "http://photos.tld/index.json", :type => :json
|
9
|
+
|
10
|
+
path :photos, :photo
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# it_should_behave_like "all sources"
|
15
|
+
|
16
|
+
it "should have been activated" do
|
17
|
+
Smoke[:photos].should(be_an_instance_of(Smoke::Source::Data))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be a list of things" do
|
21
|
+
Smoke[:photos].output.should be_an_instance_of(Array)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should respond to url" do
|
25
|
+
Smoke[:photos].should respond_to(:url)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should hold the url used to query" do
|
29
|
+
Smoke[:photos].request.uri.should == "http://photos.tld/index.json"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "results" do
|
33
|
+
it "should have two items" do
|
34
|
+
Smoke[:photos].output.size.should == 2
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be photo objects" do
|
38
|
+
keys = [:ispublic, :title, :farm, :id, :isfamily, :server, :isfriend, :owner, :secret].each do |key|
|
39
|
+
Smoke[:photos].output.first.should(have_key(key))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "making a request to a web service without a correctly set content-type in return" do
|
45
|
+
before :each do
|
46
|
+
FakeWeb.register_uri("http://photos.tld/no-format", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'), :content_type => "text/plain")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should fail" do
|
50
|
+
@source = Smoke.data(:flickr) do
|
51
|
+
url "http://photos.tld/no-format"
|
52
|
+
path :photos, :photo
|
53
|
+
end
|
54
|
+
lambda { @source.output }.should raise_error
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not fail" do
|
58
|
+
@source = Smoke.data(:flickr) do
|
59
|
+
url "http://photos.tld/no-format", :type => :json
|
60
|
+
path :photos, :photo
|
61
|
+
end
|
62
|
+
lambda { @source.output }.should_not raise_error
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
|
2
|
+
|
3
|
+
describe "Feed" do
|
4
|
+
before :all do
|
5
|
+
FakeWeb.register_uri("http://slashdot.org/index.rdf", :file => File.join(SPEC_DIR, 'supports', 'slashdot.xml'))
|
6
|
+
|
7
|
+
@source = Smoke.feed(:slashdot) do
|
8
|
+
url "http://slashdot.org/index.rdf"
|
9
|
+
url "http://slashdot.org/index.rdf"
|
10
|
+
|
11
|
+
emit do
|
12
|
+
rename(:link => :url)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# it_should_behave_like "all sources"
|
18
|
+
|
19
|
+
it "should have been activated" do
|
20
|
+
Smoke[:slashdot].should(be_an_instance_of(Smoke::Source::Feed))
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should be a list of things" do
|
24
|
+
Smoke[:slashdot].items.should be_an_instance_of(Array)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should respond to url" do
|
28
|
+
Smoke[:slashdot].should respond_to(:url)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "after dispatch / query" do
|
32
|
+
before do
|
33
|
+
Smoke[:slashdot].output
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should accept multiple urls" do
|
37
|
+
Smoke[:slashdot].requests.should be_an_instance_of(Array)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should hold the url used to query" do
|
41
|
+
Smoke[:slashdot].requests.collect{|r| r.uri }.should include("http://slashdot.org/index.rdf")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have renamed url to link" do
|
45
|
+
Smoke[:slashdot].output.first.should have_key(:url)
|
46
|
+
Smoke[:slashdot].output.first.should_not have_key(:link)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
|
2
|
+
|
3
|
+
describe "Join" do
|
4
|
+
before :all do
|
5
|
+
@source_a = TestSource.source :a
|
6
|
+
@source_b = TestSource.source :b
|
7
|
+
@source_c = TestSource.source :c
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "joining" do
|
11
|
+
before do
|
12
|
+
@source = Smoke.join(:a, :b)
|
13
|
+
end
|
14
|
+
|
15
|
+
# it_should_behave_like "all sources"
|
16
|
+
|
17
|
+
it "should be named in a_b_joined" do
|
18
|
+
Smoke[:a_b_joined].should be_an_instance_of(Smoke::Source::Join)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should contain items from sources a and b" do
|
22
|
+
Smoke[:a_b_joined].output.size.should == (@source_a.output.size + @source_b.output.size)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should accept a block" do
|
26
|
+
lambda { Smoke.join(:a, :b, :c, Proc.new {}) }.should_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should allow sorting" do
|
30
|
+
Smoke[:a_b_joined].should respond_to(:sort)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should allow changes to output" do
|
34
|
+
Smoke[:a_b_joined].should respond_to(:output)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "dispatching" do
|
38
|
+
before :all do
|
39
|
+
FakeWeb.register_uri("http://photos.tld", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
|
40
|
+
|
41
|
+
Smoke.data(:should_dispatch) do
|
42
|
+
url "http://photos.tld"
|
43
|
+
path :photos, :photo
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should call dispatch for its children" do
|
48
|
+
Smoke[:should_dispatch].should_receive(:dispatch)
|
49
|
+
Smoke.join(:a, :should_dispatch).output
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
|
2
|
+
|
3
|
+
describe "YQL" do
|
4
|
+
before :all do
|
5
|
+
FakeWeb.register_uri("http://query.yahooapis.com:80/v1/public/yql?q=SELECT%20*%20FROM%20search.web%20WHERE%20query%20=%20'ruby'&format=json", :response => File.join(SPEC_DIR, 'supports', 'search-web.json.yql'))
|
6
|
+
|
7
|
+
@source = Smoke.yql(:search) do
|
8
|
+
select :all
|
9
|
+
from "search.web"
|
10
|
+
where :query, "ruby"
|
11
|
+
path :query, :results, :result
|
12
|
+
|
13
|
+
emit do
|
14
|
+
rename(:url => :link)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# it_should_behave_like "all sources"
|
20
|
+
|
21
|
+
it "should have been activated" do
|
22
|
+
Smoke[:search].should(be_an_instance_of(Smoke::Source::YQL))
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be a list of things" do
|
26
|
+
Smoke[:search].items.should be_an_instance_of(Array)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "select" do
|
30
|
+
before do
|
31
|
+
FakeWeb.register_uri("http://query.yahooapis.com:80/v1/public/yql?q=SELECT%20url%20FROM%20search.images%20WHERE%20query%20=%20'amc%20pacer'&format=json", :response => File.join(SPEC_DIR, 'supports', 'amc_pacer.json.yql'))
|
32
|
+
|
33
|
+
Smoke.yql(:pacer) do
|
34
|
+
select :url
|
35
|
+
from "search.images"
|
36
|
+
where :query, "amc pacer"
|
37
|
+
|
38
|
+
path :query, :results, :result
|
39
|
+
end
|
40
|
+
|
41
|
+
Smoke[:pacer].output
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should query correctly" do
|
45
|
+
Smoke[:pacer].request.uri.should == "http://query.yahooapis.com/v1/public/yql?q=SELECT%20url%20FROM%20search.images%20WHERE%20query%20=%20'amc%20pacer'&format=json"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have urls" do
|
49
|
+
Smoke[:pacer].output.first.should have_key(:url)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "after dispatch" do
|
54
|
+
before do
|
55
|
+
Smoke[:search].output
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "url" do
|
59
|
+
it "should contain the base uri for yql" do
|
60
|
+
Smoke[:search].request.uri.should =~ /^http:\/\/query.yahooapis.com\/v1\/public\/yql?/
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should be format=json" do
|
64
|
+
Smoke[:search].request.uri.should include("format=json")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should contain the query" do
|
68
|
+
Smoke[:search].request.uri.should include("SELECT%20*%20FROM%20search.web%20WHERE%20query%20=%20'ruby'")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should have renamed url to link" do
|
73
|
+
Smoke[:search].output.first.should have_key(:link)
|
74
|
+
Smoke[:search].output.first.should_not have_key(:url)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should output a ruby object" do
|
78
|
+
Smoke[:search].output.should be_an_instance_of(Array)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "yql definitions" do
|
83
|
+
before do
|
84
|
+
FakeWeb.register_uri("http://query.yahooapis.com:80/v1/public/yql?q=SELECT%20*%20FROM%20github.repo%20WHERE%20id%20=%20'benschwarz'%20AND%20repo%20=%20'smoke'&format=json&env=http://datatables.org/alltables.env", :response => File.join(SPEC_DIR, 'supports', 'datatables.yql'))
|
85
|
+
|
86
|
+
Smoke.yql(:smoke) do
|
87
|
+
use "http://datatables.org/alltables.env"
|
88
|
+
|
89
|
+
select :all
|
90
|
+
from "github.repo"
|
91
|
+
where :id, "benschwarz"
|
92
|
+
where :repo, "smoke"
|
93
|
+
path :query, :results
|
94
|
+
end
|
95
|
+
|
96
|
+
Smoke[:smoke].output # Force execution
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should be a respository" do
|
100
|
+
Smoke[:smoke].output.first.should have_key(:repository)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should respond to use" do
|
104
|
+
Smoke[:smoke].should respond_to(:use)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should contain 'env' within the query string" do
|
108
|
+
Smoke[:smoke].request.uri.should =~ /env=/
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|