nsisam 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "json"
6
+ gem "sinatra"
6
7
 
7
8
  # Add dependencies to develop your gem here.
8
9
  # Include everything needed to run rake, tests, features, etc.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -0,0 +1,62 @@
1
+ require "logger"
2
+ require "sinatra"
3
+ require "json"
4
+ require "thread"
5
+ require "errors"
6
+
7
+ module FakeServer
8
+
9
+ class Server < Sinatra::Application
10
+
11
+ configure :development do
12
+ Dir.mkdir('logs') unless File.exist?('logs')
13
+ $stderr.reopen("logs/output.log", "w")
14
+ end
15
+
16
+ put "/" do
17
+ content_type :json
18
+ incoming = JSON.parse(request.body.read)
19
+ {key: "value #{incoming["value"]} stored", checksum: "0"}.to_json
20
+ end
21
+
22
+ get "/" do
23
+ content_type :json
24
+ incoming = JSON.parse(request.body.read)
25
+ return 404 if incoming["key"].include? "dont"
26
+ {
27
+ metadata: "this is the metadata",
28
+ data: "data for key #{incoming["key"]}"
29
+ }.to_json
30
+ end
31
+
32
+ delete "/" do
33
+ content_type :json
34
+ incoming = JSON.parse(request.body.read)
35
+ return 404 if incoming["key"].include? "dont"
36
+ deleted = incoming["key"].include?("delete")
37
+ {deleted: deleted}.to_json
38
+ end
39
+
40
+ post "/" do
41
+ content_type :json
42
+ incoming = JSON.parse(request.body.read)
43
+ return 404 if incoming["key"].include? "dont"
44
+ {key: incoming["key"], checksum: 0}.to_json
45
+ end
46
+ end
47
+
48
+ class FakeServerManager
49
+ def start_server
50
+ @thread = Thread.new do
51
+ Server.run! :port => 8888
52
+ end
53
+ sleep(1)
54
+ self
55
+ end
56
+
57
+ def stop_server
58
+ @thread.kill
59
+ end
60
+ end
61
+ end
62
+
data/lib/nsisam.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'client'
2
+ require 'fake_server'
2
3
 
3
4
  module NSISam
4
5
  include Client
6
+ include FakeServer
5
7
 
6
8
  end
data/nsisam.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "nsisam"
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Douglas Camata"]
12
- s.date = "2012-02-12"
12
+ s.date = "2012-02-15"
13
13
  s.description = "A simple gem to access a SAM node. For more info about SAM\n visit www.github.com/nsi-iff/sam_buildout."
14
14
  s.email = "d.camata@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "lib/client.rb",
28
28
  "lib/errors.rb",
29
+ "lib/fake_server.rb",
29
30
  "lib/nsisam.rb",
30
31
  "nsisam.gemspec",
31
32
  "spec/nsisam_spec.rb",
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
42
43
 
43
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
45
  s.add_runtime_dependency(%q<json>, [">= 0"])
46
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
45
47
  s.add_development_dependency(%q<rake>, [">= 0"])
46
48
  s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
47
49
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
@@ -50,6 +52,7 @@ Gem::Specification.new do |s|
50
52
  s.add_development_dependency(%q<simplecov>, [">= 0"])
51
53
  else
52
54
  s.add_dependency(%q<json>, [">= 0"])
55
+ s.add_dependency(%q<sinatra>, [">= 0"])
53
56
  s.add_dependency(%q<rake>, [">= 0"])
54
57
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
55
58
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -59,6 +62,7 @@ Gem::Specification.new do |s|
59
62
  end
60
63
  else
61
64
  s.add_dependency(%q<json>, [">= 0"])
65
+ s.add_dependency(%q<sinatra>, [">= 0"])
62
66
  s.add_dependency(%q<rake>, [">= 0"])
63
67
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
64
68
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
data/spec/nsisam_spec.rb CHANGED
@@ -5,10 +5,11 @@ describe NSISam do
5
5
  before :all do
6
6
  @nsisam = NSISam::Client.new 'http://test:test@localhost:8888'
7
7
  @keys = Array.new
8
+ @fake_sam = NSISam::FakeServerManager.new.start_server
8
9
  end
9
10
 
10
11
  after :all do
11
- @keys.each { |key| @nsisam.delete(key) }
12
+ @fake_sam.stop_server
12
13
  end
13
14
 
14
15
  context "storing" do
@@ -17,15 +18,13 @@ describe NSISam do
17
18
  response.should_not be_nil
18
19
  response.should have_key("key")
19
20
  response.should have_key("checksum")
20
-
21
- @keys.push(response["key"])
22
21
  end
23
22
  end
24
23
 
25
24
  context "deleting" do
26
25
  it "can delete a stored value" do
27
- key = @nsisam.store("delete this")["key"]
28
- response = @nsisam.delete(key)
26
+ @nsisam.store("delete this")["key"].should == 'value delete this stored'
27
+ response = @nsisam.delete("delete this")
29
28
  response["deleted"].should be_true
30
29
  end
31
30
 
@@ -36,30 +35,26 @@ describe NSISam do
36
35
 
37
36
  context "retrieving" do
38
37
  it "can retrieve a stored value" do
39
- key = @nsisam.store("retrieve this")["key"]
40
- response = @nsisam.get(key)
41
- response["data"].should == "retrieve this"
42
-
43
- @keys.push(key)
38
+ @nsisam.store("retrieve this")["key"].should == 'value retrieve this stored'
39
+ response = @nsisam.get('retrieve this')
40
+ response["data"].should == "data for key retrieve this"
44
41
  end
45
42
 
46
43
  it "raises error when key not found" do
47
- expect { @nsisam.get("non existing key") }.to raise_error(NSISam::Errors::Client::KeyNotFoundError)
44
+ expect { @nsisam.get("i dont exist") }.to raise_error(NSISam::Errors::Client::KeyNotFoundError)
48
45
  end
49
46
  end
50
47
 
51
48
  context "updating" do
52
49
  it "can update values in keys already stored" do
53
- key = @nsisam.store("update this")["key"]
54
- response = @nsisam.update(key, "updated")
55
- response["key"].should == key
50
+ @nsisam.store("update this")["key"].should == 'value update this stored'
51
+ response = @nsisam.update('update this', "updated")
52
+ response["key"].should == 'update this'
56
53
  response.should have_key("checksum")
57
-
58
- @keys.push(key)
59
54
  end
60
55
 
61
56
  it "raises error when key not found" do
62
- expect { @nsisam.update("ruby is fast", "foo") }.to raise_error(NSISam::Errors::Client::KeyNotFoundError)
57
+ expect { @nsisam.update("dont exist ruby is fast", "foo") }.to raise_error(NSISam::Errors::Client::KeyNotFoundError)
63
58
  end
64
59
  end
65
60
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsisam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-12 00:00:00.000000000 Z
12
+ date: 2012-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70252524589480 !ruby/object:Gem::Requirement
16
+ requirement: &70362386480220 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70252524589480
24
+ version_requirements: *70362386480220
25
+ - !ruby/object:Gem::Dependency
26
+ name: sinatra
27
+ requirement: &70362386478820 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70362386478820
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rake
27
- requirement: &70252524588120 !ruby/object:Gem::Requirement
38
+ requirement: &70362386493740 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70252524588120
46
+ version_requirements: *70362386493740
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: rspec
38
- requirement: &70252524584740 !ruby/object:Gem::Requirement
49
+ requirement: &70362386491140 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ~>
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: 2.8.0
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70252524584740
57
+ version_requirements: *70362386491140
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rdoc
49
- requirement: &70252524533140 !ruby/object:Gem::Requirement
60
+ requirement: &70362386490240 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '3.12'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70252524533140
68
+ version_requirements: *70362386490240
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: bundler
60
- requirement: &70252524530400 !ruby/object:Gem::Requirement
71
+ requirement: &70362386489400 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ~>
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: 1.0.0
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70252524530400
79
+ version_requirements: *70362386489400
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: jeweler
71
- requirement: &70252524529100 !ruby/object:Gem::Requirement
82
+ requirement: &70362386488720 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ~>
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: 1.8.3
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70252524529100
90
+ version_requirements: *70362386488720
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: simplecov
82
- requirement: &70252524528200 !ruby/object:Gem::Requirement
93
+ requirement: &70362386487900 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,7 +98,7 @@ dependencies:
87
98
  version: '0'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *70252524528200
101
+ version_requirements: *70362386487900
91
102
  description: ! "A simple gem to access a SAM node. For more info about SAM\n visit
92
103
  www.github.com/nsi-iff/sam_buildout."
93
104
  email: d.camata@gmail.com
@@ -106,6 +117,7 @@ files:
106
117
  - VERSION
107
118
  - lib/client.rb
108
119
  - lib/errors.rb
120
+ - lib/fake_server.rb
109
121
  - lib/nsisam.rb
110
122
  - nsisam.gemspec
111
123
  - spec/nsisam_spec.rb
@@ -125,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
137
  version: '0'
126
138
  segments:
127
139
  - 0
128
- hash: 4537102661431384406
140
+ hash: -642523278506786029
129
141
  required_rubygems_version: !ruby/object:Gem::Requirement
130
142
  none: false
131
143
  requirements: