Skip to content

Commit

Permalink
some refactoring/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Feb 24, 2016
1 parent 1dde851 commit e356f75
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

desc 'launch rspec tests'
task :spec do
Expand Down
6 changes: 2 additions & 4 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ require 'rubygems'
require 'sinatra'
require File.expand_path '../app/main.rb', __FILE__

run Rack::URLMap.new({
'/' => HieravizApp::Web,
'/v1' => HieravizApp::ApiV1
})
run Rack::URLMap.new('/' => HieravizApp::Web,
'/v1' => HieravizApp::ApiV1)
37 changes: 18 additions & 19 deletions hieraviz.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "hieraviz"
spec.name = 'hieraviz'
spec.version = File.read(File.expand_path('../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/]
spec.authors = ["mose"]
spec.email = ["mose@gandi.net"]
spec.authors = ['mose']
spec.email = ['mose@gandi.net']

spec.summary = %q{Web and API server for accessing Puppet dev and prod data.}
spec.description = %q{Simple web application for accessing Puppet development code
and production data in a unified interface. Its main goal is
to enable a better visibility on the Puppet architecture for
more actors to be able to interact with it.}
spec.summary = 'Web and API server for accessing Puppet dev and prod data.'
spec.description = 'Simple web application for accessing Puppet development code
and production data in a unified interface. Its main goal is
to enable a better visibility on the Puppet architecture for
more actors to be able to interact with it.'

spec.homepage = "https://github.com/Gandi/hieraviz"
spec.metadata = { "changelog" => "https://github.com/Gandi/hieraviz/blob/master/CHANGELOG.md" }
spec.license = "MIT"
spec.homepage = 'https://github.com/Gandi/hieraviz'
spec.metadata = { 'changelog' => 'https://github.com/Gandi/hieraviz/blob/master/CHANGELOG.md' }
spec.license = 'MIT'

spec.files = Dir.glob("{bin,lib,app}/**/*") +
spec.files = Dir.glob('{bin,lib,app}/**/*') +
%w(CHANGELOG.md LICENSE.txt README.md config.ru)
spec.bindir = "bin"
spec.bindir = 'bin'
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = Dir.glob("spec/**/*")
spec.require_paths = ["lib"]
spec.test_files = Dir.glob('spec/**/*')
spec.require_paths = ['lib']

spec.add_dependency 'dotenv'
spec.add_dependency 'oauth2'
Expand All @@ -33,14 +33,13 @@ Gem::Specification.new do |spec|
spec.add_dependency 'sinatra-flash'
spec.add_dependency 'hieracles', '~> 0.3.5'

spec.add_development_dependency "bundler", "~> 1.10"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec"
spec.add_development_dependency 'bundler', '~> 1.10'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'shotgun'
spec.add_development_dependency 'better_errors'
spec.add_development_dependency 'bundler-audit'
spec.add_development_dependency 'rubocop'

end
28 changes: 14 additions & 14 deletions spec/app/apiv1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
get '/blahblah'
end
it { expect(last_response).not_to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end
end

Expand All @@ -27,7 +27,7 @@
get '/not_logged'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end
end

Expand All @@ -51,7 +51,7 @@
get '/unauthorized'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end
end

Expand All @@ -70,7 +70,7 @@
get '/nodes'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end

describe 'GET /v1/node/node1.example.com/info' do
Expand All @@ -87,7 +87,7 @@
get '/node/node1.example.com/info'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end

describe 'GET /v1/node/node1.example.com/params' do
Expand All @@ -110,7 +110,7 @@
get '/node/node1.example.com/params'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end

describe 'GET /v1/node/node1.example.com' do
Expand All @@ -133,7 +133,7 @@
get '/node/node1.example.com'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end

describe 'GET /v1/node/node1.example.com/allparams' do
Expand Down Expand Up @@ -171,7 +171,7 @@
get '/node/node1.example.com/allparams'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end

describe 'GET /v1/node/node1.example.com/facts' do
Expand All @@ -181,7 +181,7 @@
get '/node/node1.example.com/facts'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end
context 'when some facts are recorded' do
let(:tmpdir) { 'spec/files/tmp' }
Expand All @@ -197,7 +197,7 @@
get '/node/node1.example.com/facts'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq data }
it { expect(JSON.parse(last_response.body)).to eq data }
end
end

Expand Down Expand Up @@ -234,7 +234,7 @@
get '/farms'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end

describe 'GET /v1/vars' do
Expand All @@ -243,7 +243,7 @@
get '/vars'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end

describe 'GET /v1/node/node1.example.com/hierarchy' do
Expand Down Expand Up @@ -277,7 +277,7 @@
get '/node/node1.example.com/hierarchy'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end

describe 'GET /v1/farm/dev' do
Expand All @@ -294,7 +294,7 @@
get '/farm/dev'
end
it { expect(last_response).to be_ok }
it { expect(JSON.parse last_response.body).to eq expected }
it { expect(JSON.parse(last_response.body)).to eq expected }
end
end
end
6 changes: 3 additions & 3 deletions spec/lib/auth_gitlab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
.to receive(:new)
.and_return(AccessTokenMock.new)
end
it { expect(oauth2.authorized? token).to eq true }
it { expect(oauth2.authorized?(token)).to eq true }
end
context 'without a valid authorization' do
let(:settings) do
Expand All @@ -102,12 +102,12 @@
.to receive(:new)
.and_return(AccessTokenMock.new)
end
it { expect(oauth2.authorized? token).to eq false }
it { expect(oauth2.authorized?(token)).to eq false }
end
end
context 'when no authorization is required' do
let(:token) { '123456' }
it { expect(oauth2.authorized? token).to be_truthy }
it { expect(oauth2.authorized?(token)).to be_truthy }
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
context 'when path starts with a slash' do
let(:path) { '/some/path' }
let(:expected) { path }
it { expect(Hieraviz::Config.root_path path).to eq expected }
it { expect(Hieraviz::Config.root_path(path)).to eq expected }
end
context 'when path don\'t start with a slash' do
let(:path) { 'relative/path' }
let(:expected) { File.expand_path(File.join('../../../', path), __FILE__) }
it { expect(Hieraviz::Config.root_path path).to eq expected }
it { expect(Hieraviz::Config.root_path(path)).to eq expected }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
it { expect(facts.read).to eq data }
end
context 'when there is no facts recorded' do
it { expect(facts.read).to eq Hash.new }
it { expect(facts.read).to eq({}) }
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/puppetdb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Hieraviz::Puppetdb do
let(:ppdb) { Hieraviz::Puppetdb.new Hash.new }
let(:ppdb) { Hieraviz::Puppetdb.new({}) }

describe '.new' do
it { expect(ppdb.instance_variable_get(:@request)).to be_a Hieracles::Puppetdb::Request }
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

describe Hieraviz::Store do
describe '.data' do
it { expect(Hieraviz::Store.data).to eq Hash.new }
it { expect(Hieraviz::Store.data).to eq({}) }
end

describe '.set' do
Expand Down Expand Up @@ -103,7 +103,7 @@
let(:tmpdir_nodir) { File.expand_path('../../files/tmp_tmp', __FILE__) }
before do
allow(Hieraviz::Config).to receive(:load).and_return('tmpdir' => tmpdir_nodir)
tmpexpect = Hieraviz::Store.init_tmpdir
Hieraviz::Store.init_tmpdir
end
after do
FileUtils.rm_rf(tmpdir_nodir) if Dir.exist?(tmpdir_nodir)
Expand Down

0 comments on commit e356f75

Please sign in to comment.