Skip to content
Browse files

fix specs for api change

  • Loading branch information...
1 parent daa052f commit 42fff91cfd193db74fdef8b90f6754f24bf1cc71 @dmytro committed Sep 26, 2012
Showing with 62 additions and 28 deletions.
  1. +31 −0 Guardfile
  2. +21 −18 app.rb
  3. +2 −2 spec/01_nagira_response_spec.rb
  4. +7 −7 spec/02_nagira_data_spec.rb
  5. +1 −1 spec/03_api_spec.rb
View
31 Guardfile
@@ -0,0 +1,31 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'brakeman' do
+ watch(%r{^app/.+\.(erb|haml|rhtml|rb)$})
+ watch(%r{^config/.+\.rb$})
+ watch(%r{^lib/.+\.rb$})
+ watch('Gemfile')
+end
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+
+ # Turnip features and steps
+ watch(%r{^spec/acceptance/(.+)\.feature$})
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
+end
+
View
39 app.rb
@@ -27,18 +27,18 @@
#
# @!macro [new] list
#
-# - +/list+ : Short list of available objects, depending on the
+# - +/_list+ : Short list of available objects, depending on the
# current request context: hosts, services, etc.
#
# @!macro [new] state
#
-# - +/state+ - Instead of full status information send only
+# - +/_state+ - Instead of full status information send only
# current state. For hosts up/down, for services OK, Warn,
# Critical, Unknown (0,1,2-1)
#
# @!macro [new] full
#
-# - +/full+ - Show full status information
+# - +/_full+ - Show full status information
# TODO Not implemented
#
@@ -99,7 +99,10 @@ class Nagira < Sinatra::Base
end
##
- # TODO
+ # @method clear_instance_data
+ # @overload before("clear data")
+ #
+ # Clear values onf instance variables before start.
#
before do
@data = []
@@ -148,13 +151,13 @@ class Nagira < Sinatra::Base
#
# = Examples
#
- # GET /objects/list # => :list
- # GET /status/state # => :state
- # GET /status/:hostname # => :full
- # GET /status # => :full
+ # GET /_objects/_list # => :list
+ # GET /_status/_state # => :state
+ # GET /_status/:hostname # => :full
+ # GET /_status # => :full
#
before do
- request.path_info.sub!(/\/(list|state)$/, '')
+ request.path_info.sub!(/\/_(list|state)$/, '')
@output = ($1 || :full).to_sym
end
@@ -232,7 +235,7 @@ class Nagira < Sinatra::Base
#
# Get Nagios configuration hash form parsing main Nagios
# configuration file nagios.cfg
- get "/config" do
+ get "/_config" do
@data = $nagios[:config].configuration
nil
end
@@ -251,7 +254,7 @@ class Nagira < Sinatra::Base
# @macro accepted
# @macro list
#
- get "/objects" do
+ get "/_objects" do
@data = begin
@output == :list ? @objects.keys : @objects
@@ -271,7 +274,7 @@ class Nagira < Sinatra::Base
# @!macro list
#
#
- get "/objects/:type" do |type|
+ get "/_objects/:type" do |type|
begin
@data = @objects[type.to_sym]
@data = @data.keys if @output == :list
@@ -293,7 +296,7 @@ class Nagira < Sinatra::Base
# @!macro accepted
# * none
#
- get "/objects/:type/:name" do |type,name|
+ get "/_objects/:type/:name" do |type,name|
begin
@data = @objects[type.to_sym][name]
rescue NoMethodError
@@ -319,7 +322,7 @@ class Nagira < Sinatra::Base
# @!macro accepted
# @!macro state
#
- get "/status/:hostname/services/:service_name" do |hostname,service|
+ get "/_status/:hostname/_services/:service_name" do |hostname,service|
if @output == :state
@data = @status[hostname]['servicestatus'][service].slice("hostname", "service_description", "current_state")
@@ -339,7 +342,7 @@ class Nagira < Sinatra::Base
# @!macro state
# @!macro list
# @!macro full
- get "/status/:hostname/services" do |hostname|
+ get "/_status/:hostname/_services" do |hostname|
case @output
when :list
@@ -362,7 +365,7 @@ class Nagira < Sinatra::Base
# @!macro accepted
# @!macro state
#
- get "/status/:hostname" do |hostname|
+ get "/_status/:hostname" do |hostname|
@data = @status[hostname]['hoststatus'].dup
if @output == :state
@@ -382,7 +385,7 @@ class Nagira < Sinatra::Base
# @!macro list
# @!macro full
#
- get "/status" do
+ get "/_status" do
@data = @status.dup
case @output
@@ -401,7 +404,7 @@ class Nagira < Sinatra::Base
#
# Provide information about API routes
#
- get "/api" do
+ get "/_api" do
@data = self.api
nil
end
View
4 spec/01_nagira_response_spec.rb
@@ -13,7 +13,7 @@ def app
@app ||= Nagira
end
- TOP_PAGES = %w{ config objects status api }
+ TOP_PAGES = %w{ _config _objects _status _api }
FORMATS = %w{ xml yaml json}
DEFAULT_FORMAT = ::Nagira.settings.format
TYPES = %w{state list}
@@ -88,7 +88,7 @@ def app
context "/config" do
before do
- get "/config.json"
+ get "/_config.json"
@data = JSON.parse last_response.body
end
View
14 spec/02_nagira_data_spec.rb
@@ -35,7 +35,7 @@ def app
context "/objects" do
before :all do
- get "/objects"
+ get "/_objects"
@data = JSON.parse last_response.body
# make sure these exist
@@ -53,15 +53,15 @@ def app
end
%w{host service contact timeperiod}.each do |obj|
- context "/objects/#{obj}" do
+ context "/_objects/#{obj}" do
it "should respond to HTTP resuest" do
- get "/objects/#{obj}.json"
+ get "/_objects/#{obj}.json"
last_response.should be_ok
end
it "response to /objects/#{obj} should be Hash" do
- get "/objects/#{obj}.json"
+ get "/_objects/#{obj}.json"
JSON.parse(last_response.body).should be_a_kind_of Hash
end
end
@@ -76,13 +76,13 @@ def app
context '/status' do
before :all do
- get "/status"
+ get "/_status"
@data = JSON.parse last_response.body
- get "/status/list"
+ get "/_status/_list"
@list = JSON.parse last_response.body
- get "/status/state"
+ get "/_status/_state"
@state = JSON.parse last_response.body
end
View
2 spec/03_api_spec.rb
@@ -17,7 +17,7 @@ def app
context "API data" do
before :all do
- get "/api.json"
+ get "/_api.json"
@data = JSON.parse last_response.body
end

0 comments on commit 42fff91

Please sign in to comment.
Something went wrong with that request. Please try again.