memcached-manager 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +13 -5
  2. data/.travis.yml +1 -1
  3. data/CONTRIBUTING.md +4 -4
  4. data/Dockerfile +7 -0
  5. data/Gemfile +0 -1
  6. data/Gemfile.lock +23 -19
  7. data/README.rdoc +8 -5
  8. data/Rakefile +6 -6
  9. data/VERSION +1 -1
  10. data/features/api/run_command.feature +6 -0
  11. data/features/api/search_memcached_keys.feature +6 -0
  12. data/features/step_definitions/api/create_memcached_key.rb +1 -1
  13. data/features/step_definitions/api/list_memcached_keys.rb +1 -0
  14. data/features/step_definitions/api/run_command.rb +12 -0
  15. data/features/step_definitions/api/search_memcached_keys.rb +6 -0
  16. data/features/step_definitions/webapp/create_memcached_key.rb +13 -7
  17. data/features/step_definitions/webapp/delete_memcached_key.rb +7 -13
  18. data/features/step_definitions/webapp/edit_configs.rb +7 -0
  19. data/features/support/env.rb +3 -2
  20. data/features/webapp/edit_configs.feature +9 -0
  21. data/features/webapp/edit_memcached_key.feature +1 -1
  22. data/fig.yml +13 -0
  23. data/githubpage_idea +23 -0
  24. data/lib/api.rb +25 -7
  25. data/lib/extensions.rb +6 -0
  26. data/lib/extensions/memcached_command.rb +14 -0
  27. data/lib/extensions/memcached_connection.rb +9 -0
  28. data/lib/extensions/memcached_inspector.rb +12 -5
  29. data/lib/extensions/memcached_settings.rb +2 -2
  30. data/lib/public/images/favicon.png +0 -0
  31. data/lib/public/images/glyphicons-halflings.png +0 -0
  32. data/lib/public/images/logo.png +0 -0
  33. data/lib/public/images/org-logo.png +0 -0
  34. data/lib/public/images/search.png +0 -0
  35. data/lib/public/javascripts/angular/controllers.js +48 -3
  36. data/lib/public/javascripts/angular/filters.js +85 -0
  37. data/lib/public/javascripts/angular/routes.js +26 -0
  38. data/lib/public/javascripts/angular/services/notification.js +41 -6
  39. data/lib/public/javascripts/angular/services/query_params_singleton.js +10 -0
  40. data/lib/public/javascripts/angular/services/resources.js +13 -0
  41. data/lib/public/javascripts/application.js +38 -1
  42. data/lib/public/javascripts/humanize.js +473 -0
  43. data/lib/public/javascripts/humanize_duration.js +329 -0
  44. data/lib/public/javascripts/jquery-terminal.js +4335 -0
  45. data/lib/public/javascripts/underscore.js +5 -0
  46. data/lib/public/stylesheets/app.css +196 -10
  47. data/lib/public/stylesheets/buttons.css +107 -0
  48. data/lib/public/stylesheets/inputs.css +119 -0
  49. data/lib/public/stylesheets/jquery-terminal.css +184 -0
  50. data/lib/public/stylesheets/media_queries.css +162 -0
  51. data/lib/public/templates/config.html.erb +8 -0
  52. data/lib/public/templates/edit.html.erb +5 -3
  53. data/lib/public/templates/keys.html.erb +42 -31
  54. data/lib/public/templates/new.html.erb +6 -4
  55. data/lib/public/templates/show.html.erb +1 -1
  56. data/lib/public/templates/stats.html.erb +1 -2
  57. data/lib/routes.rb +3 -0
  58. data/lib/views/index.erb +24 -3
  59. data/lib/views/layout.erb +14 -1
  60. data/memcached-manager.gemspec +31 -5
  61. data/spec/lib/extensions/api_response_spec.rb +9 -7
  62. data/spec/lib/extensions/memcached_command_spec.rb +13 -0
  63. data/spec/lib/extensions/memcached_connection_spec.rb +9 -4
  64. data/spec/lib/extensions/memcached_inspector_spec.rb +38 -17
  65. data/spec/lib/extensions/memcached_settings_spec.rb +16 -16
  66. data/spec/spec_helper.rb +2 -4
  67. metadata +48 -21
@@ -1,2 +1,2 @@
1
- <h2>Key: {{ pair.key }}</h2>
1
+ <h1>Key: {{ pair.key }}</h1>
2
2
  <p>{{ pair.value }}</p>
@@ -1,6 +1,5 @@
1
- <h2>Stats</h2>
1
+ <h1>Stats</h1>
2
2
  <div ng-repeat="(server, stat) in stats">
3
- <hr>
4
3
  <h3>Server: {{ server }}</h3>
5
4
  <ul ng-repeat="(key, value) in stat">
6
5
  <li><strong>{{ key }}:</strong> {{ value }}</li>
@@ -1,3 +1,6 @@
1
+ require_relative 'webapp'
2
+ require_relative 'api'
3
+
1
4
  MemcachedManager::Routes = Rack::URLMap.new({
2
5
  "/api" => MemcachedManager::API.new,
3
6
  "/" => MemcachedManager::Webapp.new
@@ -1,13 +1,34 @@
1
1
  <div class="container">
2
- <div class="sixteen columns" style="margin-top: 40px;">
2
+ <div class="sixteen columns">
3
3
  </div><!-- sixteen column -->
4
4
  <div class="one-third column">
5
5
  <div ui-view="keys"></div>
6
6
  </div><!-- two-third column -->
7
- <div class="two-third column">
8
- <div ui-view="key"></div>
7
+ <div class="two-third column" id="right-side">
8
+ <div class='menu-container'>
9
+ <a href="#/new" class="push_button green-desktop">
10
+ <span class='icon-plus icon-white spaced-icon'></span>New key
11
+ </a>
12
+ <a href="#/stats" class="push_button green-desktop">
13
+ <span class='icon-align-left icon-white spaced-icon'></span>Stats
14
+ </a>
15
+ <a href="#" id="openTerminal" class="push_button green-desktop">
16
+ <span class='icon-off icon-white spaced-icon'></span>Terminal
17
+ </a>
18
+ <a href="#/config" class="push_button green-desktop">
19
+ <span class='icon-cog icon-white spaced-icon'></span>Settings
20
+ </a>
21
+ </div>
22
+
23
+ <div ui-view="key" class="text-content">
24
+ </div><!-- text-content -->
9
25
  </div><!-- two-third column -->
10
26
  </div><!-- container -->
11
27
 
28
+
29
+ <div class='bottom-container'>
30
+ <div id='terminal'></div>
31
+ </div>
32
+
12
33
  <!-- This controller is used to bootstrap the application -->
13
34
  <section ng-controller='BootstrapController'></section>
@@ -22,6 +22,10 @@
22
22
  <link rel="stylesheet" href="<%= @engine_path %>/stylesheets/layout.css">
23
23
  <link rel="stylesheet" href="<%= @engine_path %>/stylesheets/icons.css">
24
24
  <link rel="stylesheet" href="<%= @engine_path %>/stylesheets/app.css">
25
+ <link rel="stylesheet" href="<%= @engine_path %>/stylesheets/buttons.css">
26
+ <link rel="stylesheet" href="<%= @engine_path %>/stylesheets/inputs.css">
27
+ <link rel="stylesheet" href="<%= @engine_path %>/stylesheets/jquery-terminal.css">
28
+ <link rel="stylesheet" href="<%= @engine_path %>/stylesheets/media_queries.css">
25
29
 
26
30
  <!--[if lt IE 9]>
27
31
  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
@@ -29,27 +33,36 @@
29
33
 
30
34
  <!-- Favicons
31
35
  ================================================== -->
32
- <link rel="shortcut icon" href="images/favicon.ico">
36
+ <link rel="shortcut icon" href="images/favicon.png">
33
37
  </head>
34
38
  <body>
35
39
  <%= yield %>
36
40
  <script type='text/javascript'>
37
41
  // This is used because sometimes the app is a Rails/Rack mounted application and it's base path is different.
38
42
  window.basePath = '<%= @engine_path %>';
43
+
44
+ // Variables that hold state in the angular.js app
45
+ window.stateVariables = {};
39
46
  </script>
40
47
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/jquery-1.9.1.min.js'></script>
48
+ <script type='text/javascript' src='<%= @engine_path %>/javascripts/underscore.js'></script>
41
49
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular.min.js'></script>
42
50
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular-resource.min.js'></script>
43
51
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular-ui-states.min.js'></script>
52
+ <script type='text/javascript' src='<%= @engine_path %>/javascripts/humanize.js'></script>
53
+ <script type='text/javascript' src='<%= @engine_path %>/javascripts/humanize_duration.js'></script>
44
54
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/application.js'></script>
45
55
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular/routes.js'></script>
46
56
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular/controllers.js'></script>
57
+ <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular/filters.js'></script>
47
58
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular/services/notification.js'></script>
48
59
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular/services/response.js'></script>
49
60
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular/services/resources.js'></script>
61
+ <script type='text/javascript' src='<%= @engine_path %>/javascripts/angular/services/query_params_singleton.js'></script>
50
62
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/noty/jquery.noty.js'></script>
51
63
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/noty/layouts/top.js'></script>
52
64
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/noty/themes/default.js'></script>
53
65
  <script type='text/javascript' src='<%= @engine_path %>/javascripts/noty_config.js'></script>
66
+ <script type='text/javascript' src='<%= @engine_path %>/javascripts/jquery-terminal.js'></script>
54
67
  </body>
55
68
  </html>
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: memcached-manager 0.4.0 ruby lib
5
+ # stub: memcached-manager 1.0.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "memcached-manager"
9
- s.version = "0.4.0"
9
+ s.version = "1.0.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Thiago Fernandes Massa"]
14
- s.date = "2014-05-02"
14
+ s.date = "2015-02-07"
15
15
  s.description = "A sinatra memcached-manager that allows you to view status, flush/view keys and so on. Also easily pluggable to a Rails app."
16
16
  s.email = "thiagown@gmail.com"
17
17
  s.executables = ["memcached-manager"]
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  ".rspec",
24
24
  ".travis.yml",
25
25
  "CONTRIBUTING.md",
26
+ "Dockerfile",
26
27
  "Gemfile",
27
28
  "Gemfile.lock",
28
29
  "LICENSE.txt",
@@ -34,6 +35,8 @@ Gem::Specification.new do |s|
34
35
  "features/api/create_memcached_key.feature",
35
36
  "features/api/delete_memcached_key.feature",
36
37
  "features/api/list_memcached_keys.feature",
38
+ "features/api/run_command.feature",
39
+ "features/api/search_memcached_keys.feature",
37
40
  "features/api/set_memcached_info.feature",
38
41
  "features/api/show_memcached_key.feature",
39
42
  "features/api/show_memcached_stats.feature",
@@ -41,12 +44,15 @@ Gem::Specification.new do |s|
41
44
  "features/step_definitions/api/create_memcached_key.rb",
42
45
  "features/step_definitions/api/delete_memcached_key.rb",
43
46
  "features/step_definitions/api/list_memcached_keys.rb",
47
+ "features/step_definitions/api/run_command.rb",
48
+ "features/step_definitions/api/search_memcached_keys.rb",
44
49
  "features/step_definitions/api/show_memcached_key.rb",
45
50
  "features/step_definitions/api/show_memcached_stats.rb",
46
51
  "features/step_definitions/api/update_memcached_key.rb",
47
52
  "features/step_definitions/set_memcached_info.rb",
48
53
  "features/step_definitions/webapp/create_memcached_key.rb",
49
54
  "features/step_definitions/webapp/delete_memcached_key.rb",
55
+ "features/step_definitions/webapp/edit_configs.rb",
50
56
  "features/step_definitions/webapp/edit_memcached_key.rb",
51
57
  "features/step_definitions/webapp/list_memcached_keys.rb",
52
58
  "features/step_definitions/webapp/show_memcached_key.rb",
@@ -55,39 +61,58 @@ Gem::Specification.new do |s|
55
61
  "features/support/hooks.rb",
56
62
  "features/webapp/create_memcached_key.feature",
57
63
  "features/webapp/delete_memcached_key.feature",
64
+ "features/webapp/edit_configs.feature",
58
65
  "features/webapp/edit_memcached_key.feature",
59
66
  "features/webapp/list_memcached_keys.feature",
60
67
  "features/webapp/show_memcached_key.feature",
61
68
  "features/webapp/show_memcached_stats.feature",
69
+ "fig.yml",
70
+ "githubpage_idea",
62
71
  "lib/api.rb",
63
72
  "lib/extensions.rb",
64
73
  "lib/extensions/api_response.rb",
65
74
  "lib/extensions/errors.rb",
75
+ "lib/extensions/memcached_command.rb",
66
76
  "lib/extensions/memcached_connection.rb",
67
77
  "lib/extensions/memcached_inspector.rb",
68
78
  "lib/extensions/memcached_settings.rb",
69
79
  "lib/memcached-manager.rb",
80
+ "lib/public/images/favicon.png",
70
81
  "lib/public/images/glyphicons-halflings-white.png",
71
82
  "lib/public/images/glyphicons-halflings.png",
83
+ "lib/public/images/logo.png",
84
+ "lib/public/images/org-logo.png",
85
+ "lib/public/images/search.png",
72
86
  "lib/public/javascripts/angular-resource.min.js",
73
87
  "lib/public/javascripts/angular-ui-states.min.js",
74
88
  "lib/public/javascripts/angular.min.js",
75
89
  "lib/public/javascripts/angular/controllers.js",
90
+ "lib/public/javascripts/angular/filters.js",
76
91
  "lib/public/javascripts/angular/routes.js",
77
92
  "lib/public/javascripts/angular/services/notification.js",
93
+ "lib/public/javascripts/angular/services/query_params_singleton.js",
78
94
  "lib/public/javascripts/angular/services/resources.js",
79
95
  "lib/public/javascripts/angular/services/response.js",
80
96
  "lib/public/javascripts/application.js",
97
+ "lib/public/javascripts/humanize.js",
98
+ "lib/public/javascripts/humanize_duration.js",
81
99
  "lib/public/javascripts/jquery-1.9.1.min.js",
100
+ "lib/public/javascripts/jquery-terminal.js",
82
101
  "lib/public/javascripts/noty/jquery.noty.js",
83
102
  "lib/public/javascripts/noty/layouts/top.js",
84
103
  "lib/public/javascripts/noty/themes/default.js",
85
104
  "lib/public/javascripts/noty_config.js",
105
+ "lib/public/javascripts/underscore.js",
86
106
  "lib/public/stylesheets/app.css",
87
107
  "lib/public/stylesheets/base.css",
108
+ "lib/public/stylesheets/buttons.css",
88
109
  "lib/public/stylesheets/icons.css",
110
+ "lib/public/stylesheets/inputs.css",
111
+ "lib/public/stylesheets/jquery-terminal.css",
89
112
  "lib/public/stylesheets/layout.css",
113
+ "lib/public/stylesheets/media_queries.css",
90
114
  "lib/public/stylesheets/skeleton.css",
115
+ "lib/public/templates/config.html.erb",
91
116
  "lib/public/templates/edit.html.erb",
92
117
  "lib/public/templates/keys.html.erb",
93
118
  "lib/public/templates/new.html.erb",
@@ -108,6 +133,7 @@ Gem::Specification.new do |s|
108
133
  "spec/javascripts/support/jasmine_helper.rb",
109
134
  "spec/lib/extensions/api_response_spec.rb",
110
135
  "spec/lib/extensions/error_spec.rb",
136
+ "spec/lib/extensions/memcached_command_spec.rb",
111
137
  "spec/lib/extensions/memcached_connection_spec.rb",
112
138
  "spec/lib/extensions/memcached_inspector_spec.rb",
113
139
  "spec/lib/extensions/memcached_settings_spec.rb",
@@ -115,9 +141,9 @@ Gem::Specification.new do |s|
115
141
  ]
116
142
  s.homepage = "http://github.com/thiagofm/memcached-manager"
117
143
  s.licenses = ["MIT"]
118
- s.rubygems_version = "2.2.2"
144
+ s.rubygems_version = "2.4.5"
119
145
  s.summary = "A sinatra memcached-manager that allows you to view status, flush/view keys and so on. Also easily pluggable to a Rails app."
120
- s.test_files = ["spec/javascripts", "spec/javascripts/angular", "spec/javascripts/angular/controllers", "spec/javascripts/angular/controllers/list_keys_controller_spec.js", "spec/javascripts/angular/services", "spec/javascripts/angular/services/notification_spec.js", "spec/javascripts/angular/services/resource_spec.js", "spec/javascripts/angular/services/response_spec.js", "spec/javascripts/helpers", "spec/javascripts/helpers/angular-mocks.js", "spec/javascripts/helpers/SpecHelper.js", "spec/javascripts/support", "spec/javascripts/support/jasmine.yml", "spec/javascripts/support/jasmine_helper.rb", "spec/lib", "spec/lib/extensions", "spec/lib/extensions/api_response_spec.rb", "spec/lib/extensions/error_spec.rb", "spec/lib/extensions/memcached_connection_spec.rb", "spec/lib/extensions/memcached_inspector_spec.rb", "spec/lib/extensions/memcached_settings_spec.rb", "spec/spec_helper.rb"]
146
+ s.test_files = ["spec/javascripts", "spec/javascripts/angular", "spec/javascripts/angular/controllers", "spec/javascripts/angular/controllers/list_keys_controller_spec.js", "spec/javascripts/angular/services", "spec/javascripts/angular/services/notification_spec.js", "spec/javascripts/angular/services/resource_spec.js", "spec/javascripts/angular/services/response_spec.js", "spec/javascripts/helpers", "spec/javascripts/helpers/angular-mocks.js", "spec/javascripts/helpers/SpecHelper.js", "spec/javascripts/support", "spec/javascripts/support/jasmine.yml", "spec/javascripts/support/jasmine_helper.rb", "spec/lib", "spec/lib/extensions", "spec/lib/extensions/api_response_spec.rb", "spec/lib/extensions/error_spec.rb", "spec/lib/extensions/memcached_command_spec.rb", "spec/lib/extensions/memcached_connection_spec.rb", "spec/lib/extensions/memcached_inspector_spec.rb", "spec/lib/extensions/memcached_settings_spec.rb", "spec/spec_helper.rb"]
121
147
 
122
148
  if s.respond_to? :specification_version then
123
149
  s.specification_version = 4
@@ -6,22 +6,24 @@ require 'spec_helper'
6
6
  describe Sinatra::APIResponse do
7
7
  context "#api_response" do
8
8
  it "should have a block given" do
9
- lambda { Class.new.extend(Sinatra::APIResponse).api_response }.should raise_error('No block given')
9
+ expect { Class.new.extend(Sinatra::APIResponse).api_response }.to raise_error('No block given')
10
10
  end
11
11
 
12
12
  context 'error' do
13
+ let(:klass) { Class.new.extend(Sinatra::APIResponse) }
14
+
13
15
  it "should respond with the errors" do
14
- klass = Class.new.extend(Sinatra::APIResponse)
15
- klass.stubs(:errors).returns([{foo: 'bar'}])
16
- klass.api_response {{yeah: 'yeahs'}}.should =~ /errors.*foo.*bar/
16
+ allow(klass).to receive(:errors).and_return([{foo: 'bar'}])
17
+ expect(klass.api_response {{yeah: 'yeahs'}}).to match /errors.*foo.*bar/
17
18
  end
18
19
  end
19
20
 
20
21
  context 'no error' do
22
+ let(:klass) { Class.new.extend(Sinatra::APIResponse) }
23
+
21
24
  it "should respond with what's inside the block" do
22
- klass = Class.new.extend(Sinatra::APIResponse)
23
- klass.stubs(:errors).returns([])
24
- klass.api_response { {foo: 'bar'} }.should =~ /foo.*bar/
25
+ allow(klass).to receive(:errors).and_return([])
26
+ expect(klass.api_response { {foo: 'bar'} }).to match /foo.*bar/
25
27
  end
26
28
  end
27
29
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sinatra::MemcachedCommand do
4
+ let(:host) { ENV['MEMCACHED_1_PORT_11211_TCP_ADDR'] || 'localhost' }
5
+ let(:port) { '11211' }
6
+ let(:memcached_connection) { Dalli::Client.new("#{host}:#{port}") }
7
+ let(:klass) { Class.new.extend(Sinatra::MemcachedCommand) }
8
+
9
+ it 'runs a command in memcached' do
10
+ memcached_connection.set('hello', 'world')
11
+ expect(klass.memcached_command(host: host, port: port, command: 'get hello')[:response]).to match /world/
12
+ end
13
+ end
@@ -4,8 +4,8 @@ describe Sinatra::MemcachedConnection do
4
4
  let(:klass) { Class.new.extend(Sinatra::MemcachedConnection) }
5
5
 
6
6
  context "#setup_memcached" do
7
- before(:each) { klass.setup_memcached 'localhost', '1337' }
8
- it { klass.should have_instance_variable(:memcached) }
7
+ before { klass.setup_memcached 'localhost', '1337' }
8
+ it { expect(klass).to have_instance_variable(:memcached) }
9
9
  end
10
10
 
11
11
  context "#close_memcached" do
@@ -16,10 +16,15 @@ describe Sinatra::MemcachedConnection do
16
16
  end
17
17
 
18
18
  context "#memcached_connection" do
19
- before(:each) { klass.setup_memcached 'localhost', '1337' }
19
+ before { klass.setup_memcached 'localhost', '1337' }
20
20
 
21
21
  it "should be the instance variable of memcached" do
22
- klass.instance_variable_get(:"@memcached").should be klass.memcached_connection
22
+ expect(klass.instance_variable_get(:"@memcached")).to eq klass.memcached_connection
23
23
  end
24
24
  end
25
+
26
+ context '#memcached_connected?', wip: true do
27
+ it { expect(klass.memcached_connected?('localhost', '11211')).to be_truthy }
28
+ it { expect(klass.memcached_connected?('localhost', '1121')).to be_falsy }
29
+ end
25
30
  end
@@ -1,41 +1,62 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Sinatra::MemcachedInspector do
4
- let(:host) { 'localhost' }
5
- let(:port) { '11211' }
4
+ let!(:host) { ENV['MEMCACHED_1_PORT_11211_TCP_ADDR'] || 'localhost' }
5
+ let!(:port) { '11211' }
6
6
  let(:memcached_connection) { Dalli::Client.new("#{host}:#{port}") }
7
7
  let(:klass) { Class.new.extend(Sinatra::MemcachedInspector) }
8
8
 
9
9
  context "#memcached_inspect" do
10
10
  context 'undefined key' do
11
11
  before(:each) do
12
+ memcached_connection.flush_all
12
13
  memcached_connection.set('hello', 'world')
13
14
  memcached_connection.set('question', "Who's John Galt?")
14
- @response = klass.memcached_inspect host: host, port: port
15
15
  end
16
16
 
17
- it { @response.should be_an_instance_of Array }
18
- it { @response.size.should == 2 }
19
- it { @response.first.keys.should include :key }
20
- it { @response.first.keys.should include :bytes }
21
- it { @response.first.keys.should include :expired }
22
- it { @response.first[:key].should == 'hello' }
23
- it { @response.first[:expired].should == true }
17
+ let(:response) { klass.memcached_inspect host: host, port: port }
18
+
19
+ it { expect(response).to be_an_instance_of Array }
20
+ it { expect(response.first.keys).to include :key }
21
+ it { expect(response.first.keys).to include :bytes }
22
+ it { expect(response.first.keys).to include :expires_in }
23
+ it { expect(response.first[:key]).to eq 'hello' }
24
+ it { expect(response.first[:expires_in]).to be_an_instance_of Fixnum }
24
25
  end
25
26
 
26
27
  context 'defined key' do
27
28
  before(:each) do
29
+ memcached_connection.flush_all
28
30
  memcached_connection.set('hello', 'world')
29
- memcached_connection.set('question', "Who's John Galt?")
31
+ memcached_connection.set('question', "eho's John Galt?")
30
32
  @response = klass.memcached_inspect host: host, port: port, key: 'hello'
31
33
  end
32
34
 
33
- it { @response.should_not be_an_instance_of Array }
34
- it { @response.should include :key }
35
- it { @response.should include :bytes }
36
- it { @response.should include :expired }
37
- it { @response[:key].should == 'hello' }
38
- it { @response[:expired].should == true }
35
+ it { expect(@response).to_not be_an_instance_of Array }
36
+ it { expect(@response).to include :key }
37
+ it { expect(@response).to include :bytes }
38
+ it { expect(@response).to include :expires_in }
39
+ it { expect(@response[:key]).to eq 'hello' }
40
+ it { expect(@response[:expires_in]).to be_an_instance_of Fixnum }
41
+ end
42
+
43
+ context 'defined query' do
44
+ before(:each) do
45
+ memcached_connection.flush_all
46
+ memcached_connection.set('foo1', 'world')
47
+ memcached_connection.set('foo', 'world')
48
+ memcached_connection.set('xpto', "Who's John Galt?")
49
+ @response = klass.memcached_inspect host: host, port: port, query: 'foo'
50
+ end
51
+
52
+ it { expect(@response).to be_an_instance_of Array }
53
+ it { expect(@response.size).to be 2 }
54
+ it { expect(@response.first).to include :key }
55
+ it { expect(@response.first).to include :bytes }
56
+ it { expect(@response.first.keys).to include :expires_in }
57
+ it { expect(@response.first[:key]).to eq 'foo' }
58
+ it { expect(@response.last[:key]).to eq 'foo1' }
59
+ it { expect(@response.first[:expires_in]).to be_an_instance_of Fixnum }
39
60
  end
40
61
  end
41
62
  end
@@ -1,42 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Sinatra::MemcachedSettings do
4
- let(:configured_session) { { 'host' => 'i.am', 'port' => '1337' } }
4
+ let(:configured_session) { { :host => 'i.am', :port => '1337' } }
5
5
  let(:empty_session) { {} }
6
6
  let(:klass) { Class.new.extend(Sinatra::MemcachedSettings) }
7
-
7
+
8
8
  before :each do
9
- ENV.stubs(:[]).with("memcached_host").returns(nil)
10
- ENV.stubs(:[]).with("memcached_port").returns(nil)
9
+ allow(ENV).to receive(:[]).with('memcached_host').and_return nil
10
+ allow(ENV).to receive(:[]).with('memcached_port').and_return nil
11
11
  end
12
12
 
13
13
  context '#memcached_host' do
14
14
  it "host exists" do
15
- klass.memcached_host(configured_session).should eql 'i.am'
15
+ expect(klass.memcached_host(configured_session)).to eq 'i.am'
16
16
  end
17
17
 
18
18
  it "host doesn't exist" do
19
- klass.memcached_host(empty_session).should eql 'localhost'
19
+ expect(klass.memcached_host(empty_session)).to eq 'localhost'
20
20
  end
21
21
 
22
22
  it "host is set as an env variable" do
23
- ENV.stubs(:[]).with("memcached_host").returns('ruby-lang.org')
24
- klass.memcached_host(empty_session).should eql 'ruby-lang.org'
23
+ allow(ENV).to receive(:[]).with("memcached_host").and_return('ruby-lang.org')
24
+ expect(klass.memcached_host(empty_session)).to eq 'ruby-lang.org'
25
25
  end
26
26
  end
27
27
 
28
28
  context '#memcached_port' do
29
29
  it "port exists" do
30
- klass.memcached_port(configured_session).should eql '1337'
30
+ expect(klass.memcached_port(configured_session)).to eq '1337'
31
31
  end
32
32
 
33
33
  it "port doesn't exist" do
34
- klass.memcached_port(empty_session).should eql '11211'
34
+ expect(klass.memcached_port(empty_session)).to eq '11211'
35
35
  end
36
36
 
37
37
  it "port is set as an env variable" do
38
- ENV.stubs(:[]).with("memcached_port").returns('9000')
39
- klass.memcached_port(empty_session).should eql '9000'
38
+ allow(ENV).to receive(:[]).with("memcached_port").and_return('9000')
39
+ expect(klass.memcached_port(empty_session)).to eq '9000'
40
40
  end
41
41
  end
42
42
 
@@ -45,11 +45,11 @@ describe Sinatra::MemcachedSettings do
45
45
  let(:configured_host) { {'host' => 'i.am'} }
46
46
 
47
47
  it "should be configured" do
48
- klass.send(:configured?, configured_host, 'host').should be true
48
+ expect(klass.send(:configured?, configured_host, 'host')).to be true
49
49
  end
50
50
 
51
51
  it "should not be configured" do
52
- klass.send(:configured?, configured_host, 'port').should be false
52
+ expect(klass.send(:configured?, configured_host, 'port')).to be false
53
53
  end
54
54
  end
55
55
 
@@ -57,11 +57,11 @@ describe Sinatra::MemcachedSettings do
57
57
  let(:configured_port) { {'port' => '1337'} }
58
58
 
59
59
  it "should be configured" do
60
- klass.send(:configured?, configured_port, 'port').should be true
60
+ expect(klass.send(:configured?, configured_port, 'port')).to be true
61
61
  end
62
62
 
63
63
  it "should not be configured" do
64
- klass.send(:configured?, configured_port, 'host').should be false
64
+ expect(klass.send(:configured?, configured_port, 'host')).to be false
65
65
  end
66
66
  end
67
67
  end