stairs 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -36
  3. data/.travis.yml +6 -2
  4. data/Guardfile +2 -2
  5. data/Rakefile +4 -4
  6. data/bin/stairs +10 -10
  7. data/lib/stairs.rb +13 -13
  8. data/lib/stairs/env_adapters.rb +6 -6
  9. data/lib/stairs/env_adapters/dotenv.rb +3 -3
  10. data/lib/stairs/env_adapters/rbenv.rb +3 -3
  11. data/lib/stairs/env_adapters/rvm.rb +3 -3
  12. data/lib/stairs/interactive_configuration.rb +11 -11
  13. data/lib/stairs/railtie.rb +1 -1
  14. data/lib/stairs/runner.rb +2 -2
  15. data/lib/stairs/step.rb +20 -17
  16. data/lib/stairs/steps.rb +3 -3
  17. data/lib/stairs/steps/facebook.rb +6 -6
  18. data/lib/stairs/steps/postgresql.rb +11 -11
  19. data/lib/stairs/steps/secret_key_base.rb +4 -4
  20. data/lib/stairs/tasks.rb +2 -2
  21. data/lib/stairs/util.rb +2 -2
  22. data/lib/stairs/util/cli.rb +3 -4
  23. data/lib/stairs/util/file_mutation.rb +10 -10
  24. data/lib/stairs/version.rb +1 -1
  25. data/spec/lib/configuration_spec.rb +8 -8
  26. data/spec/lib/stairs/env_adapters/dotenv_spec.rb +20 -20
  27. data/spec/lib/stairs/env_adapters/rbenv_spec.rb +22 -22
  28. data/spec/lib/stairs/env_adapters/rvm_spec.rb +22 -22
  29. data/spec/lib/stairs/env_adapters_spec.rb +12 -14
  30. data/spec/lib/stairs/interactive_configuration_spec.rb +27 -20
  31. data/spec/lib/stairs/runner_spec.rb +18 -14
  32. data/spec/lib/stairs/script_spec.rb +13 -14
  33. data/spec/lib/stairs/step_spec.rb +225 -189
  34. data/spec/lib/stairs/steps/secret_key_base_spec.rb +7 -5
  35. data/spec/lib/stairs/util/cli_spec.rb +29 -29
  36. data/spec/lib/stairs/util/file_mutation_spec.rb +46 -46
  37. data/spec/spec_helper.rb +6 -8
  38. data/stairs.gemspec +28 -23
  39. metadata +22 -23
  40. data/spec/support/configuration_helper.rb +0 -5
@@ -1,8 +1,8 @@
1
1
  module Stairs
2
2
  module Steps
3
3
  class Postgresql < Stairs::Step
4
- title "PostgreSQL"
5
- description "Setup database.yml for PostgreSQL"
4
+ title 'PostgreSQL'
5
+ description 'Setup database.yml for PostgreSQL'
6
6
 
7
7
  def run
8
8
  set_database_name
@@ -10,36 +10,36 @@ module Stairs
10
10
  set_username
11
11
  set_password
12
12
 
13
- write contents, "config/database.yml"
13
+ write contents, 'config/database.yml'
14
14
  end
15
15
 
16
16
  private
17
17
 
18
18
  def set_database_name
19
19
  contents.gsub!(
20
- "{{database_name}}",
21
- provide("Database name", default: "#{app_name}_development"),
20
+ '{{database_name}}',
21
+ provide('Database name', default: "#{app_name}_development")
22
22
  )
23
23
  end
24
24
 
25
25
  def set_test_database_name
26
26
  contents.gsub!(
27
- "{{test_database_name}}",
28
- provide("Test database name", default: "#{app_name}_test"),
27
+ '{{test_database_name}}',
28
+ provide('Test database name', default: "#{app_name}_test")
29
29
  )
30
30
  end
31
31
 
32
32
  def set_username
33
33
  contents.gsub!(
34
- "{{username}}",
35
- provide("User", default: `whoami`.strip),
34
+ '{{username}}',
35
+ provide('User', default: `whoami`.strip)
36
36
  )
37
37
  end
38
38
 
39
39
  def set_password
40
40
  contents.gsub!(
41
- "{{password}}",
42
- provide("Password", default: ""),
41
+ '{{password}}',
42
+ provide('Password', default: '')
43
43
  )
44
44
  end
45
45
 
@@ -1,13 +1,13 @@
1
- require "securerandom"
1
+ require 'securerandom'
2
2
 
3
3
  module Stairs
4
4
  module Steps
5
5
  class SecretKeyBase < Step
6
- title "Secret Token"
7
- description "Generate a secure random secret token"
6
+ title 'Secret Token'
7
+ description 'Generate a secure random secret token'
8
8
 
9
9
  def run
10
- env "SECRET_KEY_BASE", SecureRandom.hex(64)
10
+ env 'SECRET_KEY_BASE', SecureRandom.hex(64)
11
11
  end
12
12
  end
13
13
  end
@@ -1,11 +1,11 @@
1
- require "stairs"
1
+ require 'stairs'
2
2
 
3
3
  module Stairs
4
4
  class Tasks
5
5
  include Rake::DSL
6
6
 
7
7
  def install!
8
- desc "Setup the project"
8
+ desc 'Setup the project'
9
9
  task :newb do
10
10
  Stairs::Runner.new([:newb]).run!
11
11
  end
@@ -1,6 +1,6 @@
1
1
  module Stairs
2
2
  module Util
3
- autoload :FileMutation, "stairs/util/file_mutation"
4
- autoload :CLI, "stairs/util/cli"
3
+ autoload :FileMutation, 'stairs/util/file_mutation'
4
+ autoload :CLI, 'stairs/util/cli'
5
5
  end
6
6
  end
@@ -13,17 +13,16 @@ module Stairs
13
13
  end
14
14
  end
15
15
 
16
- private
17
-
18
16
  class Collector
19
- def initialize(prompt, options={}, &block)
17
+ def initialize(prompt, options = {}, &block)
20
18
  @prompt = prompt
21
19
  @options = options.reverse_merge required: true
22
20
  @validator = block
23
21
  end
24
22
 
25
23
  def run
26
- times, value = 0, nil
24
+ times = 0
25
+ value = nil
27
26
 
28
27
  until valid?(value, times)
29
28
  value = CLI.get(prompt.blue)
@@ -3,7 +3,7 @@ module Stairs
3
3
  module FileMutation
4
4
  class << self
5
5
  def replace_or_append(pattern, string, filename)
6
- if File.exists? filename
6
+ if File.exist? filename
7
7
  contents = File.read filename
8
8
  if contents =~ pattern
9
9
  contents.sub! pattern, string
@@ -16,27 +16,27 @@ module Stairs
16
16
  end
17
17
 
18
18
  def remove(pattern, filename)
19
- return unless File.exists? filename
19
+ return unless File.exist? filename
20
20
 
21
21
  contents = File.read filename
22
- if contents =~ pattern
23
- contents.slice!(pattern)
24
- write contents, filename
25
- end
22
+ return unless contents =~ pattern
23
+
24
+ contents.slice!(pattern)
25
+ write contents, filename
26
26
  end
27
27
 
28
28
  def write_line(string, filename)
29
- File.open filename, "a+" do |file|
29
+ File.open filename, 'a+' do |file|
30
30
  # ensure file ends with newline before appending
31
- last_line = file.each_line.reduce("") { |m, l| l }
32
- file.puts "" unless last_line == "" || last_line =~ /(.*)\n/
31
+ last_line = file.each_line.reduce('') { |_m, l| l }
32
+ file.puts '' unless last_line == '' || last_line =~ /(.*)\n/
33
33
 
34
34
  file.puts string
35
35
  end
36
36
  end
37
37
 
38
38
  def write(string, filename)
39
- File.open filename, "w+" do |file|
39
+ File.open filename, 'w+' do |file|
40
40
  file.puts string
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module Stairs
2
- VERSION = "0.9.0"
2
+ VERSION = '0.10.0'.freeze
3
3
  end
@@ -1,20 +1,20 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Stairs::Configuration do
4
4
  subject { described_class.new }
5
5
 
6
- describe "attributes" do
7
- it "allows for configuration of env_adapter" do
8
- subject.env_adapter = "test"
9
- expect(subject.env_adapter).to eq "test"
6
+ describe 'attributes' do
7
+ it 'allows for configuration of env_adapter' do
8
+ subject.env_adapter = 'test'
9
+ expect(subject.env_adapter).to eq 'test'
10
10
  end
11
11
 
12
- describe "use_defaults to automatically use default values" do
13
- it "defaults to false" do
12
+ describe 'use_defaults to automatically use default values' do
13
+ it 'defaults to false' do
14
14
  expect(subject.use_defaults).to eq false
15
15
  end
16
16
 
17
- it "allows for configuration" do
17
+ it 'allows for configuration' do
18
18
  subject.use_defaults = true
19
19
  expect(subject.use_defaults).to eq true
20
20
  end
@@ -1,48 +1,48 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Stairs::EnvAdapters::Dotenv do
4
4
  subject { described_class.new }
5
5
 
6
- describe ".present?" do
7
- context "when rvm is installed" do
8
- before { stub_const "Dotenv", double("dotenv") }
6
+ describe '.present?' do
7
+ context 'when rvm is installed' do
8
+ before { stub_const 'Dotenv', double('dotenv') }
9
9
 
10
- it "returns true" do
11
- expect(described_class.present?).to be_true
10
+ it 'returns true' do
11
+ expect(described_class.present?).to eq true
12
12
  end
13
13
  end
14
14
 
15
- context "when rvm is not installed" do
15
+ context 'when rvm is not installed' do
16
16
  before { Object.send(:remove_const, :Dotenv) if defined? ::Dotenv }
17
17
 
18
- it "returns true" do
19
- expect(described_class.present?).to be_false
18
+ it 'returns true' do
19
+ expect(described_class.present?).to eq false
20
20
  end
21
21
  end
22
22
  end
23
23
 
24
- describe "#set" do
25
- it "delegates to the well tested FileMutation util" do
26
- name = "VAR_NAME"
27
- value = "the_value"
24
+ describe '#set' do
25
+ it 'delegates to the well tested FileMutation util' do
26
+ name = 'VAR_NAME'
27
+ value = 'the_value'
28
28
 
29
- Stairs::Util::FileMutation.should_receive(:replace_or_append).with(
29
+ expect(Stairs::Util::FileMutation).to receive(:replace_or_append).with(
30
30
  Regexp.new("^#{name}=(.*)$"),
31
31
  "#{name}=#{value}",
32
- ".env",
32
+ '.env'
33
33
  )
34
34
 
35
35
  subject.set(name, value)
36
36
  end
37
37
  end
38
38
 
39
- describe "#unset" do
40
- it "delegates to the well tested FileMutation util" do
41
- Stairs::Util::FileMutation.should_receive(:remove).with(
39
+ describe '#unset' do
40
+ it 'delegates to the well tested FileMutation util' do
41
+ expect(Stairs::Util::FileMutation).to receive(:remove).with(
42
42
  Regexp.new("^SOMETHING=(.*)\n"),
43
- ".env",
43
+ '.env'
44
44
  )
45
- subject.unset "SOMETHING"
45
+ subject.unset 'SOMETHING'
46
46
  end
47
47
  end
48
48
  end
@@ -1,50 +1,50 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Stairs::EnvAdapters::Rbenv do
4
4
  subject { described_class.new }
5
5
 
6
- describe ".present?" do
7
- before { described_class.should_receive(:`).with("which rbenv-vars") }
6
+ describe '.present?' do
7
+ before { expect(described_class).to receive(:`).with('which rbenv-vars') }
8
8
 
9
- context "when rbenv-vars is installed" do
10
- before { $?.stub success?: true }
9
+ context 'when rbenv-vars is installed' do
10
+ before { allow($CHILD_STATUS).to receive(:success?).and_return(true) }
11
11
 
12
- it "returns true" do
13
- expect(described_class.present?).to be_true
12
+ it 'returns true' do
13
+ expect(described_class.present?).to eq true
14
14
  end
15
15
  end
16
16
 
17
- context "when rbenv-vars is not installed" do
18
- before { $?.stub success?: false }
17
+ context 'when rbenv-vars is not installed' do
18
+ before { allow($CHILD_STATUS).to receive(:success?).and_return(false) }
19
19
 
20
- it "returns true" do
21
- expect(described_class.present?).to be_false
20
+ it 'returns true' do
21
+ expect(described_class.present?).to eq false
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
- describe "#set" do
27
- it "delegates to the well tested FileMutation util" do
28
- name = "VAR_NAME"
29
- value = "the_value"
26
+ describe '#set' do
27
+ it 'delegates to the well tested FileMutation util' do
28
+ name = 'VAR_NAME'
29
+ value = 'the_value'
30
30
 
31
- Stairs::Util::FileMutation.should_receive(:replace_or_append).with(
31
+ expect(Stairs::Util::FileMutation).to receive(:replace_or_append).with(
32
32
  Regexp.new("^#{name}=(.*)$"),
33
33
  "#{name}=#{value}",
34
- ".rbenv-vars",
34
+ '.rbenv-vars'
35
35
  )
36
36
 
37
37
  subject.set(name, value)
38
38
  end
39
39
  end
40
40
 
41
- describe "#unset" do
42
- it "delegates to the well tested FileMutation util" do
43
- Stairs::Util::FileMutation.should_receive(:remove).with(
41
+ describe '#unset' do
42
+ it 'delegates to the well tested FileMutation util' do
43
+ expect(Stairs::Util::FileMutation).to receive(:remove).with(
44
44
  Regexp.new("^SOMETHING=(.*)\n"),
45
- ".rbenv-vars",
45
+ '.rbenv-vars'
46
46
  )
47
- subject.unset "SOMETHING"
47
+ subject.unset 'SOMETHING'
48
48
  end
49
49
  end
50
50
  end
@@ -1,50 +1,50 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Stairs::EnvAdapters::RVM do
4
4
  subject { described_class.new }
5
5
 
6
- describe ".present?" do
7
- before { described_class.should_receive(:`).with("which rvm") }
6
+ describe '.present?' do
7
+ before { expect(described_class).to receive(:`).with('which rvm') }
8
8
 
9
- context "when rvm is installed" do
10
- before { $?.stub success?: true }
9
+ context 'when rvm is installed' do
10
+ before { allow($CHILD_STATUS).to receive(:success?).and_return(true) }
11
11
 
12
- it "returns true" do
13
- expect(described_class.present?).to be_true
12
+ it 'returns true' do
13
+ expect(described_class.present?).to eq true
14
14
  end
15
15
  end
16
16
 
17
- context "when rvm is not installed" do
18
- before { $?.stub success?: false }
17
+ context 'when rvm is not installed' do
18
+ before { allow($CHILD_STATUS).to receive(:success?).and_return(false) }
19
19
 
20
- it "returns true" do
21
- expect(described_class.present?).to be_false
20
+ it 'returns true' do
21
+ expect(described_class.present?).to eq false
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
- describe "#set" do
27
- it "delegates to the well tested FileMutation util" do
28
- name = "VAR_NAME"
29
- value = "the_value"
26
+ describe '#set' do
27
+ it 'delegates to the well tested FileMutation util' do
28
+ name = 'VAR_NAME'
29
+ value = 'the_value'
30
30
 
31
- Stairs::Util::FileMutation.should_receive(:replace_or_append).with(
31
+ expect(Stairs::Util::FileMutation).to receive(:replace_or_append).with(
32
32
  Regexp.new("^export #{name}=(.*)$"),
33
33
  "export #{name}=#{value}",
34
- ".rvmrc",
34
+ '.rvmrc'
35
35
  )
36
36
 
37
37
  subject.set(name, value)
38
38
  end
39
39
  end
40
40
 
41
- describe "#unset" do
42
- it "delegates to the well tested FileMutation util" do
43
- Stairs::Util::FileMutation.should_receive(:remove).with(
41
+ describe '#unset' do
42
+ it 'delegates to the well tested FileMutation util' do
43
+ expect(Stairs::Util::FileMutation).to receive(:remove).with(
44
44
  Regexp.new("^export SOMETHING=(.*)\n"),
45
- ".rvmrc",
45
+ '.rvmrc'
46
46
  )
47
- subject.unset "SOMETHING"
47
+ subject.unset 'SOMETHING'
48
48
  end
49
49
  end
50
50
  end
@@ -1,28 +1,26 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Stairs::EnvAdapters do
4
4
  subject { described_class }
5
- let(:present_adapter) { double("adapter", present?: true) }
6
- let(:other_adapter) { double("adapter", present?: false) }
7
- let(:another_adapter) { double("adapter", present?: false) }
5
+ let(:present_adapter) { double('adapter', present?: true) }
6
+ let(:other_adapter) { double('adapter', present?: false) }
7
+ let(:another_adapter) { double('adapter', present?: false) }
8
8
 
9
9
  before do
10
- stub_const "Stairs::EnvAdapters::ADAPTERS", {
11
- one: other_adapter,
12
- two: present_adapter,
13
- three: another_adapter
14
- }
10
+ stub_const 'Stairs::EnvAdapters::ADAPTERS', one: other_adapter,
11
+ two: present_adapter,
12
+ three: another_adapter
15
13
  end
16
14
 
17
- describe ".recommended_adapter" do
18
- it "returns the first adapter to be `present?`" do
15
+ describe '.recommended_adapter' do
16
+ it 'returns the first adapter to be `present?`' do
19
17
  expect(described_class.recommended_adapter).to eq present_adapter
20
18
  end
21
19
  end
22
20
 
23
- describe ".name_for_adapter_class" do
24
- it "returns the name" do
21
+ describe '.name_for_adapter_class' do
22
+ it 'returns the name' do
25
23
  expect(described_class.name_for_adapter_class(present_adapter)).to eq :two
26
24
  end
27
25
  end
28
- end
26
+ end