From 0029c812756bc04bd9d42daa1d2ab4e72ec00978 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Mon, 9 Apr 2018 22:43:58 -0400 Subject: [PATCH 1/2] Add retriever specs --- Gemfile.lock | 5 +++ lib/psenv/version.rb | 2 +- psenv.gemspec | 1 + spec/environment_spec.rb | 2 +- spec/retriever_spec.rb | 71 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 spec/retriever_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 8ddcf6d..73b5096 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,6 +41,7 @@ GEM aws-sigv4 (~> 1.0) aws-sigv4 (1.0.2) builder (3.2.3) + coderay (1.1.2) concurrent-ruby (1.0.5) crack (0.4.3) safe_yaml (~> 1.0.0) @@ -63,6 +64,9 @@ GEM parser (2.5.0.5) ast (~> 2.4.0) powerpack (0.1.1) + pry (0.11.3) + coderay (~> 1.1.0) + method_source (~> 0.9.0) public_suffix (3.0.2) rack (2.0.4) rack-test (1.0.0) @@ -117,6 +121,7 @@ PLATFORMS DEPENDENCIES bundler (~> 1.16) + pry psenv! psenv-rails! rake (~> 10.0) diff --git a/lib/psenv/version.rb b/lib/psenv/version.rb index 885eecb..6479013 100644 --- a/lib/psenv/version.rb +++ b/lib/psenv/version.rb @@ -1,3 +1,3 @@ module Psenv - VERSION = "0.2.0".freeze + VERSION = "0.2.1".freeze end diff --git a/psenv.gemspec b/psenv.gemspec index c460ddc..c28e8d3 100644 --- a/psenv.gemspec +++ b/psenv.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.16" + spec.add_development_dependency "pry" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "rubocop", "0.54" diff --git a/spec/environment_spec.rb b/spec/environment_spec.rb index 7c15f84..4121dd0 100644 --- a/spec/environment_spec.rb +++ b/spec/environment_spec.rb @@ -49,6 +49,6 @@ RSpec.describe Psenv::Environment do it "applies duplicates based on the first provided" do expect(ENV["B"]).to eq("1") - end + end end end diff --git a/spec/retriever_spec.rb b/spec/retriever_spec.rb new file mode 100644 index 0000000..87eff01 --- /dev/null +++ b/spec/retriever_spec.rb @@ -0,0 +1,71 @@ +require "spec_helper" + +require "ostruct" + +RSpec.describe Psenv::Parameter do + context ".new" do + let(:parameter) do + { + name: "/psenv/test/VARIABLE", + value: "value", + type: "String", + version: 1, + } + end + subject { Psenv::Parameter.new(parameter) } + + it "creates a paraemeter object" do + expect(subject).to be_kind_of(Psenv::Parameter) + end + + it "stores the correct name" do + expect(subject.name).to eq("VARIABLE") + end + + it "stores the value" do + expect(subject.value).to eq("value") + end + end +end + +RSpec.describe Psenv::Retriever do + context ".new" do + it "creates a retriever object" do + expect(Psenv::Retriever.new("A")).to be_kind_of(Psenv::Retriever) + end + end + + context "#call" do + let(:ssm) { double } + before(:each) { allow(Aws::SSM::Client).to receive(:new) { ssm } } + + subject { Psenv::Retriever.new("/psenv/test").call } + + context "with a successful request" do + before(:each) do + allow(ssm).to receive(:get_parameters_by_path) { + OpenStruct.new( + parameters: [{ + name: "/psenv/test/API_KEY", + value: "value", + type: "String", + version: 1, + }], + ) + } + end + + it "returns the parsed parameters" do + expect(subject).to eq("API_KEY" => "value") + end + end + + context "when the request fails" do + before(:each) { allow(ssm).to receive(:get_parameters_by_path).and_raise } + + it "raises a RetrieveError" do + expect { subject }.to raise_error(Psenv::RetrieveError) + end + end + end +end From e30f1433fb2dcf99c8729f749be07337be5b5c48 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Mon, 9 Apr 2018 22:46:27 -0400 Subject: [PATCH 2/2] Clean up CI/CD --- .rubocop.yml | 1 + .travis.yml | 8 ++++++++ Gemfile.lock | 38 +++++++++++++++++++------------------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7f5eb68..e94ee3a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ AllCops: Exclude: - db/schema.rb + - vendor/**/* Metrics/LineLength: Description: 'Limit lines to 80 characters.' diff --git a/.travis.yml b/.travis.yml index 06bf19c..0396cef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,13 @@ sudo: false +cache: bundler language: ruby rvm: - 2.4.2 before_install: gem install bundler -v 1.16.1 + +jobs: + include: + - stage: analyze + script: bundle exec rubocop + - stage: test + script: bundle exec rspec diff --git a/Gemfile.lock b/Gemfile.lock index 73b5096..4e0e62a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,42 +1,42 @@ PATH remote: . specs: - psenv (0.2.0) + psenv (0.2.1) aws-sdk-ssm (~> 1) - psenv-rails (0.2.0) - psenv (= 0.2.0) + psenv-rails (0.2.1) + psenv (= 0.2.1) railties (>= 3.2, < 5.2) GEM remote: https://rubygems.org/ specs: - actionpack (5.1.5) - actionview (= 5.1.5) - activesupport (= 5.1.5) + actionpack (5.1.6) + actionview (= 5.1.6) + activesupport (= 5.1.6) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.5) - activesupport (= 5.1.5) + actionview (5.1.6) + activesupport (= 5.1.6) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activesupport (5.1.5) + activesupport (5.1.6) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) ast (2.4.0) - aws-partitions (1.74.0) - aws-sdk-core (3.18.0) + aws-partitions (1.79.0) + aws-sdk-core (3.19.0) aws-partitions (~> 1.0) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-ssm (1.8.0) + aws-sdk-ssm (1.10.0) aws-sdk-core (~> 3) aws-sigv4 (~> 1.0) aws-sigv4 (1.0.2) @@ -45,13 +45,13 @@ GEM concurrent-ruby (1.0.5) crack (0.4.3) safe_yaml (~> 1.0.0) - crass (1.0.3) + crass (1.0.4) diff-lcs (1.3) erubi (1.7.1) hashdiff (0.3.7) - i18n (0.9.5) + i18n (1.0.0) concurrent-ruby (~> 1.0) - jmespath (1.3.1) + jmespath (1.4.0) loofah (2.2.2) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -76,9 +76,9 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - railties (5.1.5) - actionpack (= 5.1.5) - activesupport (= 5.1.5) + railties (5.1.6) + actionpack (= 5.1.6) + activesupport (= 5.1.6) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0)