holoserve-connector 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 Skrill Holdings Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,45 @@
1
+
2
+ = HoloServe Connector - Connector library for HoloServe.
3
+
4
+ This library provides a client to the control interface of HoloServe and RSpec matchers to integrate HoloServe in a
5
+ test suite. See {holoserve}[https://github.com/skrill/holoserve] for details about the concept of HoloServe.
6
+
7
+ == Example
8
+
9
+ require 'holoserve/connector'
10
+ require 'transport'
11
+
12
+ holoserve = Holoserve::Connector.new :host => "localhost", :port => 8080
13
+
14
+ holoserve.layouts.upload_yml "./layouts/test.yml"
15
+ holoserve.layouts.current = "one"
16
+
17
+ Transport::HTTP.request :post, "/test" # handled in test layout one
18
+ Transport::HTTP.request :delete, "/test" # unhandled
19
+
20
+ holoserve.history.pair_names
21
+ # => [ "test_requested" ]
22
+
23
+ holoserve.bucket.requsts
24
+ # => [ { "method" => "DELETE", :path => "/test", :headers => { ... } } ]
25
+
26
+ == RSpec inetgration example
27
+
28
+ require 'rspec/holoserve'
29
+
30
+ RSpec::Holoserve.run_server = true
31
+
32
+ describe "RSpec matchers" do
33
+
34
+ before :all do
35
+ @client = Holoserve::Bond.new
36
+ @client.layouts.upload_yml File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "layouts", "test.yml"))
37
+ @client.layouts.current = "one"
38
+ end
39
+
40
+ it "should test if holoserve received a specified request" do
41
+ Transport::HTTP.request :post, "http://localhost:8080/test", :expected_status_code => 201
42
+ @client.should have_received("test_request")
43
+ end
44
+
45
+ end
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ begin
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+
8
+ Cucumber::Rake::Task.new(:features) do |task|
9
+ task.cucumber_opts = "features --format pretty"
10
+ end
11
+
12
+ namespace :features do
13
+
14
+ Cucumber::Rake::Task.new(:wip) do |task|
15
+ task.cucumber_opts = "features --format pretty --tags @wip"
16
+ end
17
+
18
+ end
19
+ rescue LoadError
20
+ end
21
+
22
+ begin
23
+ require 'rspec'
24
+ require 'rspec/core/rake_task'
25
+
26
+ desc "Run specs"
27
+ RSpec::Core::RakeTask.new do |task|
28
+ task.pattern = "./spec/lib/**/*_spec.rb"
29
+ end
30
+ rescue LoadError
31
+ end
32
+
33
+ begin
34
+ require 'rdoc'
35
+ require 'rdoc/task'
36
+
37
+ Rake::RDocTask.new do |rdoc|
38
+ rdoc.main = "README.rdoc"
39
+ rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
40
+ end
41
+ rescue LoadError
42
+ end
43
+
44
+ namespace :gem do
45
+
46
+ desc "Builds the gem"
47
+ task :build do
48
+ system "gem build *.gemspec && mkdir -p pkg/ && mv *.gem pkg/"
49
+ end
50
+
51
+ desc "Builds and installs the gem"
52
+ task :install => :build do
53
+ system "gem install pkg/"
54
+ end
55
+
56
+ end
@@ -0,0 +1,12 @@
1
+
2
+ class Holoserve::Connector::Bucket
3
+
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def requests
9
+ Transport::JSON.request :get, "#{@client.url}/bucket/requests"
10
+ end
11
+
12
+ end
@@ -0,0 +1,16 @@
1
+
2
+ class Holoserve::Connector::History
3
+
4
+ def initialize(client)
5
+ @client = client
6
+ end
7
+
8
+ def clear!
9
+ Transport::JSON.request :delete, "#{@client.url}/history"
10
+ end
11
+
12
+ def pair_names
13
+ Transport::JSON.request :get, "#{@client.url}/history "
14
+ end
15
+
16
+ end
@@ -0,0 +1,54 @@
1
+ require 'transport'
2
+
3
+ class Holoserve::Connector::Layouts
4
+
5
+ def initialize(client)
6
+ @client = client
7
+
8
+ @boundary = "xxx12345xxx"
9
+ end
10
+
11
+ def clear!
12
+ Transport::JSON.request :delete,
13
+ "#{@client.url}/layouts",
14
+ :expected_status_code => 200
15
+ end
16
+
17
+ def upload_yml(filename)
18
+ Transport::HTTP.request :post,
19
+ "#{@client.url}/layouts",
20
+ :body => upload_yml_file_request_body(filename),
21
+ :headers => {
22
+ "Content-Type" => "multipart/form-data, boundary=#{@boundary}"
23
+ },
24
+ :expected_status_code => 200
25
+ true
26
+ rescue Transport::UnexpectedStatusCodeError => error
27
+ raise Holoserve::Connector::Error, error.message
28
+ end
29
+
30
+ def available
31
+ Transport::JSON.request :get, "#{@client.url}/layouts/ids"
32
+ end
33
+
34
+ def current=(id)
35
+ Transport::JSON.request :put, "#{@client.url}/layouts/#{id}/current"
36
+ end
37
+
38
+ def current
39
+ Transport::HTTP.request :get, "#{@client.url}/layouts/current"
40
+ end
41
+
42
+ private
43
+
44
+ def upload_yml_file_request_body(filename)
45
+ "--#{@boundary}\r\n" +
46
+ "Content-Disposition: form-data; name=\"file\"; filename=\"#{File.basename(filename)}\"\r\n" +
47
+ "Content-Type: application/x-yaml\r\n" +
48
+ "\r\n" +
49
+ File.read(filename) +
50
+ "\r\n" +
51
+ "--#{@boundary}--\r\n"
52
+ end
53
+
54
+ end
@@ -0,0 +1,31 @@
1
+
2
+ class Holoserve::Connector
3
+
4
+ autoload :Bucket, File.join(File.dirname(__FILE__), "connector", "bucket")
5
+ autoload :History, File.join(File.dirname(__FILE__), "connector", "history")
6
+ autoload :Layouts, File.join(File.dirname(__FILE__), "connector", "layouts")
7
+
8
+ class Error < StandardError; end
9
+
10
+ attr_reader :host
11
+ attr_reader :port
12
+
13
+ attr_reader :layouts
14
+ attr_reader :bucket
15
+ attr_reader :history
16
+
17
+ def initialize(options = { })
18
+ @host, @port = *options.values_at(:host, :port)
19
+ @host ||= "localhost"
20
+ @port ||= 4250
21
+
22
+ @layouts = Layouts.new self
23
+ @bucket = Bucket.new self
24
+ @history = History.new self
25
+ end
26
+
27
+ def url
28
+ "http://#{@host}:#{@port}/_control"
29
+ end
30
+
31
+ end
@@ -0,0 +1,36 @@
1
+ require 'rspec'
2
+ require 'rspec/expectations'
3
+ require 'holoserve'
4
+
5
+ RSpec.configure do |configuration|
6
+
7
+ configuration.before :suite do
8
+ if RSpec::Holoserve.run_server?
9
+ @server = ::Holoserve::Runner.new
10
+ @server.start
11
+ end
12
+ end
13
+
14
+ configuration.after :suite do
15
+ @server.stop if @server
16
+ end
17
+
18
+ end
19
+
20
+ RSpec::Matchers.define :have_received do |expected|
21
+ match do |actual|
22
+ actual.is_a?(Holoserve::Connector) && actual.history.pair_names.include?(expected)
23
+ end
24
+ end
25
+
26
+ class RSpec::Holoserve
27
+
28
+ def self.run_server=(value)
29
+ @run_server = value
30
+ end
31
+
32
+ def self.run_server?
33
+ !!@run_server
34
+ end
35
+
36
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'holoserve'
4
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "holoserve", "connector"))
@@ -0,0 +1,9 @@
1
+ one:
2
+ -
3
+ name: "test_request"
4
+ request:
5
+ method: "POST"
6
+ path: "/test"
7
+ response:
8
+ status: 201
9
+ body: "created"
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "helper"))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "rspec", "holoserve"))
3
+
4
+ RSpec::Holoserve.run_server = true
5
+
6
+ describe "RSpec matchers" do
7
+
8
+ before :all do
9
+ @client = Holoserve::Connector.new
10
+ @client.layouts.upload_yml File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "layouts", "test.yml"))
11
+ @client.layouts.current = "one"
12
+ end
13
+
14
+ it "should test if holoserve received a specified request" do
15
+ Transport::HTTP.request :post, "http://localhost:8080/test", :expected_status_code => 201
16
+ @client.should have_received("test_request")
17
+ end
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: holoserve-connector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Philipp Brüll
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: transport
16
+ requirement: &70253145056100 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70253145056100
25
+ - !ruby/object:Gem::Dependency
26
+ name: holoserve
27
+ requirement: &70253145052760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70253145052760
36
+ - !ruby/object:Gem::Dependency
37
+ name: cucumber
38
+ requirement: &70253145051660 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70253145051660
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70253145050340 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70253145050340
58
+ description: Provides a client for the control interface of holoserve and some RSpec
59
+ matchers.
60
+ email: philipp.bruell@skrill.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - README.rdoc
65
+ files:
66
+ - README.rdoc
67
+ - LICENSE
68
+ - Rakefile
69
+ - lib/holoserve/connector/bucket.rb
70
+ - lib/holoserve/connector/history.rb
71
+ - lib/holoserve/connector/layouts.rb
72
+ - lib/holoserve/connector.rb
73
+ - lib/rspec/holoserve.rb
74
+ - spec/helper.rb
75
+ - spec/layouts/test.yml
76
+ - spec/lib/rspec/holoserve_spec.rb
77
+ homepage: http://github.com/skrill/holoserve-connector
78
+ licenses: []
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ segments:
90
+ - 0
91
+ hash: 2293304529508499132
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project: holoserve-connector
100
+ rubygems_version: 1.8.10
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Connector library for HoloServe.
104
+ test_files:
105
+ - spec/lib/rspec/holoserve_spec.rb