snapsearch-client-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+ require 'rack/request'
3
+
4
+ describe SnapSearch::Interceptor do
5
+
6
+ let(:detector) { double }
7
+ let(:client) { double }
8
+ let(:encoded_url) { 'http://example.com' }
9
+ let(:mock_response) do
10
+ {
11
+ 'status' => 200,
12
+ 'headers' => {
13
+ 'name' => 'Date',
14
+ 'value' => 'Tue, 19 Nov 2013 18:23:41 GMT'
15
+ },
16
+ 'html' => '<html>Hi!</html>',
17
+ 'screenshot' => '',
18
+ 'date' => '324836'
19
+ }
20
+ end
21
+
22
+ before do
23
+ detector.stub(:detect) { true }
24
+ detector.stub(:get_encoded_url) { encoded_url }
25
+
26
+ client.stub(:request) { mock_response }
27
+ end
28
+
29
+ subject { described_class.new(client, detector) }
30
+
31
+ let(:request) { Rack::Request.new( { 'rack.input' => StringIO.new }.merge(client.request) ) }
32
+
33
+ it 'should be a Hash' do
34
+ content = subject.intercept(request: request)
35
+
36
+ content.should be_a(Hash)
37
+ end
38
+
39
+ describe 'callbacks' do
40
+
41
+ describe '#before_intercept' do
42
+
43
+ it 'should receive the current URL as a block argument' do
44
+ before_intercept_url = ''
45
+
46
+ subject.before_intercept { |url| before_intercept_url = url }
47
+
48
+ subject.intercept(request: request)
49
+
50
+ before_intercept_url.should == encoded_url
51
+ end
52
+
53
+ it 'should respond with the result of the callback if a Hash is returned' do
54
+ response_hash = { 'test' => 'value' }
55
+
56
+ subject.before_intercept { response_hash }
57
+
58
+ content = subject.intercept(request: request)
59
+
60
+ content.should == response_hash
61
+ end
62
+
63
+ it 'should not respond with the result of the callback if a Hash is not returned' do
64
+ response_string = 'i will not be the response!'
65
+
66
+ subject.before_intercept { response_string }
67
+
68
+ content = subject.intercept(request: request)
69
+
70
+ content.should_not == response_string
71
+ end
72
+
73
+ end
74
+
75
+ describe '#after_intercept' do
76
+
77
+ it 'should receive the current URL and response Hash as a block argument' do
78
+ after_intercept_url = ''
79
+ after_intercept_response_hash = nil
80
+
81
+ subject.after_intercept { |url, response| after_intercept_url, after_intercept_response_hash = url, response }
82
+
83
+ content = subject.intercept(request: request)
84
+
85
+ after_intercept_url.should == encoded_url
86
+ after_intercept_response_hash.should == content
87
+ after_intercept_response_hash.should == mock_response
88
+ end
89
+
90
+ it 'should not need to accept block arguments' do
91
+ after_intercept = nil
92
+
93
+ subject.after_intercept { after_intercept = 'whateveriwant' }
94
+
95
+ subject.intercept(request: request)
96
+
97
+ after_intercept.should == 'whateveriwant'
98
+ end
99
+
100
+ end
101
+
102
+ it 'should be able to be chained' do
103
+ before_value, after_value = '', ''
104
+
105
+ subject.
106
+ before_intercept { before_value = 'success' }.
107
+ after_intercept { after_value = 'success' }.
108
+ intercept(request: request)
109
+
110
+ before_value.should == 'success'
111
+ after_value.should == 'success'
112
+ end
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,6 @@
1
+ require 'snap_search'
2
+ require 'rack/snap_search'
3
+
4
+ RSpec.configure do |config|
5
+ config.order = 'random'
6
+ end
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snapsearch-client-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Scott Lewis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: version
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: httpi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 10.1.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 10.1.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.14.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.14.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 4.2.5
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 4.2.5
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 2.1.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 2.1.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: fuubar
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 1.3.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 1.3.2
139
+ description: Ruby HTTP Client Middleware Libraries for SnapSearch. Search engine optimisation
140
+ for single page applications.
141
+ email: roger.qiu@polycademy.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - Rakefile
147
+ - Gemfile.lock
148
+ - Gemfile
149
+ - README.md
150
+ - VERSION
151
+ - LICENSE
152
+ - snapsearch.gemspec
153
+ - lib/rack/snap_search/config.rb
154
+ - lib/rack/snap_search.rb
155
+ - lib/snap_search/client.rb
156
+ - lib/snap_search/connection_exception.rb
157
+ - lib/snap_search/detector.rb
158
+ - lib/snap_search/exception.rb
159
+ - lib/snap_search/interceptor.rb
160
+ - lib/snap_search/validation_exception.rb
161
+ - lib/snap_search.rb
162
+ - examples/rack/config.ru
163
+ - examples/rack/Gemfile
164
+ - examples/rack/public/index.html
165
+ - examples/sinatra/config.ru
166
+ - examples/sinatra/Gemfile
167
+ - examples/sinatra/Gemfile.lock
168
+ - examples/sinatra/lib/sinatra_snap_search.rb
169
+ - examples/sinatra/public/index.html
170
+ - resources/cacert.pem
171
+ - resources/extensions.json
172
+ - resources/robots.json
173
+ - spec/lib/rack/qs_spec.rb
174
+ - spec/lib/rack/snap_search/config_spec.rb
175
+ - spec/lib/snap_search/detector_spec.rb
176
+ - spec/lib/snap_search/interceptor_spec.rb
177
+ - spec/spec_helper.rb
178
+ homepage: https://github.com/SnapSearch/SnapSearch-Client-Ruby
179
+ licenses:
180
+ - MIT
181
+ metadata: {}
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubyforge_project:
198
+ rubygems_version: 2.0.3
199
+ signing_key:
200
+ specification_version: 4
201
+ summary: Ruby HTTP Client Middleware Libraries for SnapSearch. Search engine optimisation
202
+ for single page applications.
203
+ test_files:
204
+ - examples/rack/config.ru
205
+ - examples/rack/Gemfile
206
+ - examples/rack/public/index.html
207
+ - examples/sinatra/config.ru
208
+ - examples/sinatra/Gemfile
209
+ - examples/sinatra/Gemfile.lock
210
+ - examples/sinatra/lib/sinatra_snap_search.rb
211
+ - examples/sinatra/public/index.html
212
+ - spec/lib/rack/qs_spec.rb
213
+ - spec/lib/rack/snap_search/config_spec.rb
214
+ - spec/lib/snap_search/detector_spec.rb
215
+ - spec/lib/snap_search/interceptor_spec.rb
216
+ - spec/spec_helper.rb