From 76f84a3676f3de9007138bed71d1e5041f313be7 Mon Sep 17 00:00:00 2001 From: Brian Martinez <1622554+stoicAlchemist@users.noreply.github.com> Date: Tue, 10 Aug 2021 12:21:23 -0500 Subject: [PATCH 1/3] Updated versions, not working yet --- .ruby-version | 2 +- .tool-versions | 1 + Gemfile.lock | 151 +++++++++++++++++++++--------------------------- zenflow.gemspec | 14 ++--- 4 files changed, 76 insertions(+), 92 deletions(-) create mode 100644 .tool-versions diff --git a/.ruby-version b/.ruby-version index eca07e4..0cadbc1 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.1.2 +2.5.5 diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..2db3e23 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 2.5.5 diff --git a/Gemfile.lock b/Gemfile.lock index f8a97ee..c54ba20 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,110 +3,91 @@ PATH specs: zenflow (0.8.13) colored (~> 1.2) - httparty (~> 0.13.0) + httparty (~> 0.18.1) terminal-table (~> 1.4.5) thor (~> 0.19.0) GEM remote: http://rubygems.org/ specs: - addressable (2.3.6) + addressable (2.8.0) + public_suffix (>= 2.0.2, < 5.0) byebug (3.1.2) columnize (~> 0.8) debugger-linecache (~> 1.2) - celluloid (0.15.2) - timers (~> 1.1.0) - celluloid-io (0.15.0) - celluloid (>= 0.15.0) - nio4r (>= 0.5.0) - coderay (1.1.0) colored (1.2) columnize (0.8.9) - coveralls (0.7.0) + coveralls (0.7.1) multi_json (~> 1.3) rest-client simplecov (>= 0.7) term-ansicolor thor - crack (0.4.2) - safe_yaml (~> 1.0.0) + crack (0.4.5) + rexml debugger-linecache (1.2.0) - diff-lcs (1.2.5) - domain_name (0.5.23) + diff-lcs (1.4.4) + docile (1.4.0) + domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - ffi (1.9.3) - formatador (0.2.4) - fuubar (1.1.1) - rspec (~> 2.0) - rspec-instafail (~> 0.2.0) - ruby-progressbar (~> 1.0) - guard (2.6.1) - formatador (>= 0.2.4) - listen (~> 2.7) - lumberjack (~> 1.0) - pry (>= 0.9.12) - thor (>= 0.18.1) - guard-rspec (3.0.3) - guard (>= 1.8) - rspec (~> 2.13) - http-cookie (1.0.2) + fuubar (2.5.1) + rspec-core (~> 3.0) + ruby-progressbar (~> 1.4) + hashdiff (1.0.1) + http-accept (1.7.0) + http-cookie (1.0.4) domain_name (~> 0.5) - httparty (0.13.1) - json (~> 1.8) + httparty (0.18.1) + mime-types (~> 3.0) multi_xml (>= 0.5.2) - json (1.8.1) - listen (2.7.4) - celluloid (>= 0.15.2) - celluloid-io (>= 0.15.0) - rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9) - lumberjack (1.0.5) - method_source (0.8.2) - mime-types (2.4.3) - multi_json (1.10.0) - multi_xml (0.5.5) - netrc (0.10.3) - nio4r (1.0.0) - pry (0.9.12.6) - coderay (~> 1.0) - method_source (~> 0.8) - slop (~> 3.4) - rb-fsevent (0.9.4) - rb-inotify (0.9.4) - ffi (>= 0.5.0) - rest-client (1.8.0) + mime-types (3.3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2021.0704) + multi_json (1.15.0) + multi_xml (0.6.0) + netrc (0.11.0) + public_suffix (4.0.6) + rest-client (2.1.0) + http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 3.0) - netrc (~> 0.7) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.8) - rspec-expectations (2.14.5) - diff-lcs (>= 1.1.3, < 2.0) - rspec-instafail (0.2.4) - rspec-mocks (2.14.6) - ruby-progressbar (1.4.2) - safe_yaml (1.0.3) - simplecov (0.7.1) - multi_json (~> 1.0) - simplecov-html (~> 0.7.1) - simplecov-html (0.7.1) - slop (3.5.0) - term-ansicolor (1.3.0) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) + rexml (3.2.5) + rspec (3.10.0) + rspec-core (~> 3.10.0) + rspec-expectations (~> 3.10.0) + rspec-mocks (~> 3.10.0) + rspec-core (3.10.1) + rspec-support (~> 3.10.0) + rspec-expectations (3.10.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-mocks (3.10.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.2) + ruby-progressbar (1.11.0) + simplecov (0.21.2) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.3) + sync (0.5.0) + term-ansicolor (1.7.1) tins (~> 1.0) terminal-table (1.4.5) - thor (0.19.1) - timers (1.1.0) - tins (1.1.0) + thor (0.19.4) + tins (1.29.1) + sync unf (0.1.4) unf_ext - unf_ext (0.0.6) - vcr (2.5.0) - webmock (1.13.0) - addressable (>= 2.2.7) + unf_ext (0.0.7.7) + vcr (6.0.0) + webmock (3.13.0) + addressable (>= 2.3.6) crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) PLATFORMS ruby @@ -114,10 +95,12 @@ PLATFORMS DEPENDENCIES byebug coveralls - fuubar (~> 1.1.1) - guard-rspec (~> 3.0.2) - rspec (~> 2.14) - simplecov (~> 0.7.1) - vcr (~> 2.5.0) - webmock (~> 1.13.0) + fuubar (~> 2.5.1) + rspec (~> 3.10) + simplecov (~> 0.21.2) + vcr (~> 6.0.0) + webmock (~> 3.13.0) zenflow! + +BUNDLED WITH + 2.1.4 diff --git a/zenflow.gemspec b/zenflow.gemspec index db9032c..de76d22 100644 --- a/zenflow.gemspec +++ b/zenflow.gemspec @@ -20,14 +20,14 @@ Gem::Specification.new do |s| s.add_dependency "thor", "~> 0.19.0" s.add_dependency "colored", "~> 1.2" s.add_dependency "terminal-table", "~> 1.4.5" - s.add_dependency "httparty", "~> 0.13.0" - s.add_development_dependency('rspec', '~> 2.14') - s.add_development_dependency('simplecov', '~> 0.7.1') + s.add_dependency "httparty", "~> 0.18.1" + s.add_development_dependency('rspec', '~> 3.10') + s.add_development_dependency('simplecov', '~> 0.21.2') s.add_development_dependency('byebug') - s.add_development_dependency('fuubar', '~> 1.1.1') - s.add_development_dependency('guard-rspec', '~> 3.0.2') - s.add_development_dependency('vcr', '~> 2.5.0') - s.add_development_dependency('webmock', '~> 1.13.0') + s.add_development_dependency('fuubar', '~> 2.5.1') + # s.add_development_dependency('guard-rspec', '~> 3.0.2') + s.add_development_dependency('vcr', '~> 6.0.0') + s.add_development_dependency('webmock', '~> 3.13.0') s.files = `git ls-files`.split("\n") s.require_path = "lib" end From 86ae44a3a5fa2bbd9218ff38b4a1c7511576cb0d Mon Sep 17 00:00:00 2001 From: Brian Martinez <1622554+stoicAlchemist@users.noreply.github.com> Date: Mon, 16 Aug 2021 00:54:23 -0500 Subject: [PATCH 2/3] upg(all): Upgrading and updating --- .solargraph.yml | 21 ++ Gemfile | 1 + lib/zenflow/helpers/ask.rb | 9 +- spec/spec_helper.rb | 11 +- spec/zenflow/cli_spec.rb | 198 ++++++------- spec/zenflow/commands/admin_spec.rb | 50 ++-- spec/zenflow/commands/deploy_spec.rb | 18 +- spec/zenflow/commands/hotfix_spec.rb | 4 +- spec/zenflow/commands/release_spec.rb | 4 +- spec/zenflow/commands/reviews_spec.rb | 6 +- spec/zenflow/helpers/ask_spec.rb | 39 +-- spec/zenflow/helpers/branch_command_spec.rb | 306 ++++++++++---------- spec/zenflow/helpers/branch_spec.rb | 150 +++++----- spec/zenflow/helpers/changelog_spec.rb | 80 ++--- spec/zenflow/helpers/github_spec.rb | 162 +++++------ spec/zenflow/helpers/help_spec.rb | 8 +- spec/zenflow/helpers/log_spec.rb | 10 +- spec/zenflow/helpers/pull_request_spec.rb | 20 +- spec/zenflow/helpers/repo_spec.rb | 4 +- spec/zenflow/helpers/shell_spec.rb | 34 +-- spec/zenflow/helpers/version_spec.rb | 4 +- 21 files changed, 585 insertions(+), 554 deletions(-) create mode 100644 .solargraph.yml diff --git a/.solargraph.yml b/.solargraph.yml new file mode 100644 index 0000000..127d585 --- /dev/null +++ b/.solargraph.yml @@ -0,0 +1,21 @@ +--- +include: +- "**/*.rb" +exclude: +- spec/**/* +- test/**/* +- vendor/**/* +- ".bundle/**/*" +require: [] +domains: [] +reporters: +- rubocop +formatter: + rubocop: + cops: safe + except: [] + only: [] + extra_args: [] +require_paths: [] +plugins: [] +max_files: 5000 diff --git a/Gemfile b/Gemfile index 9aa5dc2..37db9c9 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,5 @@ source "http://rubygems.org" gemspec +gem 'byebug', groups: [:development, :test] gem 'coveralls', require: false diff --git a/lib/zenflow/helpers/ask.rb b/lib/zenflow/helpers/ask.rb index 2d02d64..bc9e0c8 100644 --- a/lib/zenflow/helpers/ask.rb +++ b/lib/zenflow/helpers/ask.rb @@ -6,7 +6,14 @@ def self.Ask(question, options={}) rescue StandardError => e puts e.message options[:response] = nil - retry + + print '>> Retry? [Y/n]' + retry_response = $stdin.gets.chomp + retry if ['y', 'yes', ''].include? retry_response.downcase + + puts "-----> Exiting...".cyan + LogToFile("-----> Received bad response with no retry. Exiting...") + raise e rescue Interrupt => e puts puts "-----> Exiting...".cyan diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 390975a..26bb900 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,12 @@ require 'simplecov' require 'coveralls' -SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ - SimpleCov::Formatter::HTMLFormatter, - Coveralls::SimpleCov::Formatter -] +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new( + [ + SimpleCov::Formatter::HTMLFormatter, + Coveralls::SimpleCov::Formatter + ] +) SimpleCov.start do add_filter '/spec/' end @@ -24,7 +26,6 @@ RSpec.configure do |config| config.order = "random" - config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true config.filter_run :focus => true diff --git a/spec/zenflow/cli_spec.rb b/spec/zenflow/cli_spec.rb index fcba086..3f3212d 100644 --- a/spec/zenflow/cli_spec.rb +++ b/spec/zenflow/cli_spec.rb @@ -6,15 +6,15 @@ describe "#version" do it 'outputs the version number' do - subject.should_receive(:puts).with("Zenflow #{Zenflow::VERSION}") + expect(subject).to receive(:puts).with("Zenflow #{Zenflow::VERSION}") subject.version end end describe "#help" do it 'displays helpful information' do - subject.should_receive(:version) - $stdout.should_receive(:puts).at_least(:once) + expect(subject).to receive(:version) + expect($stdout).to receive(:puts).at_least(:once) subject.help end end @@ -22,28 +22,28 @@ describe "#already_configured" do let(:question) {['There is an existing config file. Overwrite it?', {:options => ["y", "N"], :default => "n"}]} before do - Zenflow.should_receive(:Log).with('Warning', :color => :red) + expect(Zenflow).to receive(:Log).with('Warning', :color => :red) end context "when the user wants to overwrite the configuration" do before do - Zenflow.should_receive(:Ask).with(*question).and_return('y') + expect(Zenflow).to receive(:Ask).with(*question).and_return('y') end it "forces initialization" do - subject.should_receive(:init).with(true) + expect(subject).to receive(:init).with(true) subject.already_configured end end context "when the user does not want to overwrite the configuration" do before do - Zenflow.should_receive(:Ask).with(*question).and_return('n') + expect(Zenflow).to receive(:Ask).with(*question).and_return('n') end it "aborts" do - Zenflow.should_receive(:Log).with('Aborting...', :color => :red) - lambda{ subject.already_configured}.should raise_error(SystemExit) + expect(Zenflow).to receive(:Log).with('Aborting...', :color => :red) + expect(lambda{ subject.already_configured}).to raise_error(SystemExit) end end end @@ -51,23 +51,23 @@ describe "#configure_branch" do context "when the user wants to configure a staging branch" do before do - Zenflow.should_receive(:Ask).with("Use a branch for staging releases and hotfixes?", :options => ["Y", "n"], :default => "y").and_return('y') + expect(Zenflow).to receive(:Ask).with("Use a branch for staging releases and hotfixes?", :options => ["Y", "n"], :default => "y").and_return('y') end it 'names the staging branch whatever the user wants' do - Zenflow.should_receive(:Ask).with("What is the name of that branch?", :default => "staging").and_return('staging') - Zenflow::Config.should_receive(:[]=).with(:staging_branch, 'staging') + expect(Zenflow).to receive(:Ask).with("What is the name of that branch?", :default => "staging").and_return('staging') + expect(Zenflow::Config).to receive(:[]=).with(:staging_branch, 'staging') subject.configure_branch(:staging_branch, "Use a branch for staging releases and hotfixes?", 'staging') end end context "when the user does not want to configure a staging branch" do before do - Zenflow.should_receive(:Ask).with("Use a branch for staging releases and hotfixes?", :options => ["Y", "n"], :default => "y").and_return('n') + expect(Zenflow).to receive(:Ask).with("Use a branch for staging releases and hotfixes?", :options => ["Y", "n"], :default => "y").and_return('n') end it 'names the staging branch whatever the user wants' do - Zenflow::Config.should_receive(:[]=).with(:staging_branch, false) + expect(Zenflow::Config).to receive(:[]=).with(:staging_branch, false) subject.configure_branch(:staging_branch, "Use a branch for staging releases and hotfixes?", 'staging') end end @@ -76,16 +76,16 @@ describe "#configure_merge_strategy" do context "when the user wants to keep the default merge strategy of 'merge'" do it 'sets the merge strategy to merge' do - Zenflow.should_receive(:Ask).with("What merge strategy would you prefer?", :options => ["merge", "rebase"], :default => "merge").and_return('merge') - Zenflow::Config.should_receive(:[]=).with(:merge_strategy, 'merge') + expect(Zenflow).to receive(:Ask).with("What merge strategy would you prefer?", :options => ["merge", "rebase"], :default => "merge").and_return('merge') + expect(Zenflow::Config).to receive(:[]=).with(:merge_strategy, 'merge') subject.configure_merge_strategy end end context "when the user wants to change the default merge strategy to 'rebase'" do it 'sets the merge strategy to rebase' do - Zenflow.should_receive(:Ask).with("What merge strategy would you prefer?", :options => ["merge", "rebase"], :default => "merge").and_return('rebase') - Zenflow::Config.should_receive(:[]=).with(:merge_strategy, 'rebase') + expect(Zenflow).to receive(:Ask).with("What merge strategy would you prefer?", :options => ["merge", "rebase"], :default => "merge").and_return('rebase') + expect(Zenflow::Config).to receive(:[]=).with(:merge_strategy, 'rebase') subject.configure_merge_strategy end end @@ -93,19 +93,19 @@ describe "#configure_project" do it 'asks the user to name their project' do - Zenflow.should_receive(:Ask).with("What is the name of this project?", :required => true).and_return('zenflow') - Zenflow.should_receive(:Log).with("Project") - Zenflow::Config.should_receive(:[]=).with(:project, 'zenflow') + expect(Zenflow).to receive(:Ask).with("What is the name of this project?", :required => true).and_return('zenflow') + expect(Zenflow).to receive(:Log).with("Project") + expect(Zenflow::Config).to receive(:[]=).with(:project, 'zenflow') subject.configure_project end end describe "#configure_branches" do it 'configures branches for the project' do - Zenflow.should_receive(:Ask).with("What is the name of the main development branch?", :default => "master").and_return('master') - Zenflow.should_receive(:Log).with("Branches") - Zenflow::Config.should_receive(:[]=).with(:development_branch, 'master') - subject.should_receive(:configure_branch).exactly(3).times + expect(Zenflow).to receive(:Ask).with("What is the name of the main development branch?", :default => "master").and_return('master') + expect(Zenflow).to receive(:Log).with("Branches") + expect(Zenflow::Config).to receive(:[]=).with(:development_branch, 'master') + expect(subject).to receive(:configure_branch).exactly(3).times subject.configure_branches end end @@ -113,28 +113,28 @@ describe "#configure_remotes" do context "when the user wants to configure a backup remote" do before do - Zenflow.should_receive(:Ask).with("Use a backup remote?", :options => ["y", "N"], :default => "n").and_return('y') + expect(Zenflow).to receive(:Ask).with("Use a backup remote?", :options => ["y", "N"], :default => "n").and_return('y') end it 'configures the primary remote and a backup remote' do - Zenflow.should_receive(:Ask).with("What is the name of your primary remote?", :default => "origin").and_return('origin') - Zenflow::Config.should_receive(:[]=).with(:remote, 'origin') - Zenflow.should_receive(:Ask).with("What is the name of your backup remote?", :default => "backup").and_return('backup') - Zenflow::Config.should_receive(:[]=).with(:backup_remote, 'backup') + expect(Zenflow).to receive(:Ask).with("What is the name of your primary remote?", :default => "origin").and_return('origin') + expect(Zenflow::Config).to receive(:[]=).with(:remote, 'origin') + expect(Zenflow).to receive(:Ask).with("What is the name of your backup remote?", :default => "backup").and_return('backup') + expect(Zenflow::Config).to receive(:[]=).with(:backup_remote, 'backup') subject.configure_remotes end end context "when the user does not want to configure a backup remote" do before do - Zenflow.should_receive(:Ask).with("Use a backup remote?", :options => ["y", "N"], :default => "n").and_return('n') + expect(Zenflow).to receive(:Ask).with("Use a backup remote?", :options => ["y", "N"], :default => "n").and_return('n') end it 'configures the primary remote and a backup remote' do - Zenflow.should_receive(:Ask).with("What is the name of your primary remote?", :default => "origin").and_return('origin') - Zenflow::Config.should_receive(:[]=).with(:remote, 'origin') - Zenflow.should_not_receive(:Ask).with("What is the name of your backup remote?", :default => "backup") - Zenflow::Config.should_receive(:[]=).with(:backup_remote, false) + expect(Zenflow).to receive(:Ask).with("What is the name of your primary remote?", :default => "origin").and_return('origin') + expect(Zenflow::Config).to receive(:[]=).with(:remote, 'origin') + expect(Zenflow).to_not receive(:Ask).with("What is the name of your backup remote?", :default => "backup") + expect(Zenflow::Config).to receive(:[]=).with(:backup_remote, false) subject.configure_remotes end end @@ -143,22 +143,22 @@ describe "#set_up_changelog" do context "when the changelog doesn't already exist" do before do - File.should_receive(:exist?).with("CHANGELOG.md").and_return(false) - Zenflow.should_receive(:Log).with("Changelog Management") + expect(File).to receive(:exist?).with("CHANGELOG.md").and_return(false) + expect(Zenflow).to receive(:Log).with("Changelog Management") end context "when the user wants to set up a changelog" do it 'sets up the changelog' do - Zenflow.should_receive(:Ask).with("Set up a changelog?", :options => ["Y", "n"], :default => "y").and_return('y') - Zenflow::Changelog.should_receive(:create) + expect(Zenflow).to receive(:Ask).with("Set up a changelog?", :options => ["Y", "n"], :default => "y").and_return('y') + expect(Zenflow::Changelog).to receive(:create) subject.set_up_changelog end end context "when the user does not want to set up a changelog" do it 'does not set up the changelog' do - Zenflow.should_receive(:Ask).with("Set up a changelog?", :options => ["Y", "n"], :default => "y").and_return('n') - Zenflow::Changelog.should_not_receive(:create) + expect(Zenflow).to receive(:Ask).with("Set up a changelog?", :options => ["Y", "n"], :default => "y").and_return('n') + expect(Zenflow::Changelog).to_not receive(:create) subject.set_up_changelog end end @@ -166,13 +166,13 @@ context "when the changelog already exists" do before do - File.should_receive(:exist?).with("CHANGELOG.md").and_return(true) + expect(File).to receive(:exist?).with("CHANGELOG.md").and_return(true) end it 'does not set up the changelog' do - Zenflow.should_not_receive(:Log).with("Changelog Management") - Zenflow.should_not_receive(:Ask).with("Set up a changelog?", :options => ["Y", "n"], :default => "y") - Zenflow::Changelog.should_not_receive(:create) + expect(Zenflow).to_not receive(:Log).with("Changelog Management") + expect(Zenflow).to_not receive(:Ask).with("Set up a changelog?", :options => ["Y", "n"], :default => "y") + expect(Zenflow::Changelog).to_not receive(:create) subject.set_up_changelog end end @@ -180,11 +180,11 @@ describe "#confirm_some_stuff" do it "confirms staging deployment and code review requirements" do - Zenflow.should_receive(:Log).with("Confirmations") - Zenflow.should_receive(:Ask).with("Require deployment to a staging environment?", :options => ["Y", "n"], :default => "y").and_return('y') - Zenflow::Config.should_receive(:[]=).with(:confirm_staging, true) - Zenflow.should_receive(:Ask).with("Require code reviews?", :options => ["Y", "n"], :default => "y").and_return('n') - Zenflow::Config.should_receive(:[]=).with(:confirm_review, false) + expect(Zenflow).to receive(:Log).with("Confirmations") + expect(Zenflow).to receive(:Ask).with("Require deployment to a staging environment?", :options => ["Y", "n"], :default => "y").and_return('y') + expect(Zenflow::Config).to receive(:[]=).with(:confirm_staging, true) + expect(Zenflow).to receive(:Ask).with("Require code reviews?", :options => ["Y", "n"], :default => "y").and_return('n') + expect(Zenflow::Config).to receive(:[]=).with(:confirm_review, false) subject.confirm_some_stuff end end @@ -198,25 +198,25 @@ context "when in a project that doesn't belong to the default hub" do before do - current.should_receive(:is_default_hub?).and_return(false) + expect(current).to receive(:is_default_hub?).and_return(false) end context "when zenflow has not been configured" do before do - Zenflow::Config.should_receive(:configured?).and_return(false) + expect(Zenflow::Config).to receive(:configured?).and_return(false) end it 'configures zenflow' do - subject.should_not_receive(:already_configured) - current.should_receive(:config) - current.should_receive(:authorize) - subject.should_receive(:configure_project) - subject.should_receive(:configure_branches) - subject.should_receive(:configure_merge_strategy) - subject.should_receive(:configure_remotes) - subject.should_receive(:confirm_some_stuff) - subject.should_receive(:set_up_changelog) - Zenflow::Config.should_receive(:save!) + expect(subject).to_not receive(:already_configured) + expect(current).to receive(:config) + expect(current).to receive(:authorize) + expect(subject).to receive(:configure_project) + expect(subject).to receive(:configure_branches) + expect(subject).to receive(:configure_merge_strategy) + expect(subject).to receive(:configure_remotes) + expect(subject).to receive(:confirm_some_stuff) + expect(subject).to receive(:set_up_changelog) + expect(Zenflow::Config).to receive(:save!) subject.init end end @@ -224,68 +224,68 @@ context "when zenflow has not been configured" do before do - Zenflow::Config.should_receive(:configured?).and_return(false) - current.should_receive(:is_default_hub?).and_return(true) + expect(Zenflow::Config).to receive(:configured?).and_return(false) + expect(current).to receive(:is_default_hub?).and_return(true) end it 'configures zenflow' do - subject.should_not_receive(:already_configured) - current.should_receive(:set_user) - current.should_receive(:authorize) - subject.should_receive(:configure_project) - subject.should_receive(:configure_branches) - subject.should_receive(:configure_merge_strategy) - subject.should_receive(:configure_remotes) - subject.should_receive(:confirm_some_stuff) - subject.should_receive(:set_up_changelog) - Zenflow::Config.should_receive(:save!) + expect(subject).to_not receive(:already_configured) + expect(current).to receive(:set_user) + expect(current).to receive(:authorize) + expect(subject).to receive(:configure_project) + expect(subject).to receive(:configure_branches) + expect(subject).to receive(:configure_merge_strategy) + expect(subject).to receive(:configure_remotes) + expect(subject).to receive(:confirm_some_stuff) + expect(subject).to receive(:set_up_changelog) + expect(Zenflow::Config).to receive(:save!) subject.init end end context "when zenflow has already been configured" do before do - Zenflow::Config.should_receive(:configured?).and_return(true) + expect(Zenflow::Config).to receive(:configured?).and_return(true) end context 'and it is forced to initialize' do before do - current.should_receive(:is_default_hub?).and_return(true) + expect(current).to receive(:is_default_hub?).and_return(true) end it 'configures zenflow' do - subject.should_not_receive(:already_configured) - current.should_receive(:set_user) - current.should_receive(:authorize) - subject.should_receive(:configure_project) - subject.should_receive(:configure_branches) - subject.should_receive(:configure_merge_strategy) - subject.should_receive(:configure_remotes) - subject.should_receive(:confirm_some_stuff) - subject.should_receive(:set_up_changelog) - Zenflow::Config.should_receive(:save!) + expect(subject).to_not receive(:already_configured) + expect(current).to receive(:set_user) + expect(current).to receive(:authorize) + expect(subject).to receive(:configure_project) + expect(subject).to receive(:configure_branches) + expect(subject).to receive(:configure_merge_strategy) + expect(subject).to receive(:configure_remotes) + expect(subject).to receive(:confirm_some_stuff) + expect(subject).to receive(:set_up_changelog) + expect(Zenflow::Config).to receive(:save!) subject.init(true) end end context 'and it is forced to initialize' do before do - Zenflow.should_receive(:Log).with('Warning', :color => :red) - Zenflow.should_receive(:Ask).and_return('n') - Zenflow.should_receive(:Log).with('Aborting...', :color => :red) + expect(Zenflow).to receive(:Log).with('Warning', :color => :red) + expect(Zenflow).to receive(:Ask).and_return('n') + expect(Zenflow).to receive(:Log).with('Aborting...', :color => :red) end it 'calls already_configured' do - subject.should_receive(:already_configured).and_call_original - current.should_not_receive(:set_user) - current.should_not_receive(:authorize) - subject.should_not_receive(:configure_branches) - subject.should_not_receive(:configure_merge_strategy) - subject.should_not_receive(:configure_remotes) - subject.should_not_receive(:confirm_some_stuff) - subject.should_not_receive(:set_up_changelog) - Zenflow::Config.should_not_receive(:save!) - lambda{ subject.init}.should raise_error(SystemExit) + expect(subject).to receive(:already_configured).and_call_original + expect(current).to_not receive(:set_user) + expect(current).to_not receive(:authorize) + expect(subject).to_not receive(:configure_branches) + expect(subject).to_not receive(:configure_merge_strategy) + expect(subject).to_not receive(:configure_remotes) + expect(subject).to_not receive(:confirm_some_stuff) + expect(subject).to_not receive(:set_up_changelog) + expect(Zenflow::Config).to_not receive(:save!) + expect(lambda{ subject.init}).to raise_error(SystemExit) end end end diff --git a/spec/zenflow/commands/admin_spec.rb b/spec/zenflow/commands/admin_spec.rb index 065bdb6..b4f100f 100644 --- a/spec/zenflow/commands/admin_spec.rb +++ b/spec/zenflow/commands/admin_spec.rb @@ -5,7 +5,7 @@ describe '.list' do it 'lists recognized hubs in git config' do - Zenflow::Shell.should_receive(:run).with("git config --get-regexp zenflow\.hub\..*", silent: true).and_return( + expect(Zenflow::Shell).to receive(:run).with("git config --get-regexp zenflow\.hub\..*", silent: true).and_return( <false, :arrows=>false, :color=>false}) + expect(Zenflow).to receive(:Log).with("log-data", {:indent=>false, :arrows=>false, :color=>false}) admin.describe('my-hub') end end @@ -66,19 +66,19 @@ context 'when called with a hub parameter' do it 'calls the individual parameter config methods' do myhub = Zenflow::Github.new('my-hub') - Zenflow::Github.should_receive(:new).with('my-hub').and_return(myhub) - admin.should_receive(:hub_label).with('my-hub').and_return('my-hub') - Zenflow.should_receive(:Log).with("Configuring my-hub") - myhub.should_receive(:config) + expect(Zenflow::Github).to receive(:new).with('my-hub').and_return(myhub) + expect(admin).to receive(:hub_label).with('my-hub').and_return('my-hub') + expect(Zenflow).to receive(:Log).with("Configuring my-hub") + expect(myhub).to receive(:config) admin.config('my-hub') end end context 'when called with no hub parameter' do it 'calls the individual parameter config methods' do - admin.should_receive(:hub_label).with('github.com').and_return('github.com') - Zenflow.should_receive(:Log).with("Configuring github.com") - Zenflow::Github::CURRENT.should_receive(:config) + expect(admin).to receive(:hub_label).with('github.com').and_return('github.com') + expect(Zenflow).to receive(:Log).with("Configuring github.com") + expect(Zenflow::Github::CURRENT).to receive(:config) admin.config end end @@ -88,19 +88,19 @@ context 'when called with a hub parameter' do it 'call the hubs authorize method' do myhub = Zenflow::Github.new('my-hub') - Zenflow::Github.should_receive(:new).with('my-hub').and_return(myhub) - admin.should_receive(:hub_label).with('my-hub').and_return('my-hub') - Zenflow.should_receive(:Log).with("Authorizing my-hub") - myhub.should_receive(:authorize) + expect(Zenflow::Github).to receive(:new).with('my-hub').and_return(myhub) + expect(admin).to receive(:hub_label).with('my-hub').and_return('my-hub') + expect(Zenflow).to receive(:Log).with("Authorizing my-hub") + expect(myhub).to receive(:authorize) admin.authorize('my-hub') end end context 'when called with no hub parameter' do it 'call the current hubs authorize method' do - admin.should_receive(:hub_label).with('github.com').and_return('github.com') - Zenflow.should_receive(:Log).with("Authorizing github.com") - Zenflow::Github::CURRENT.should_receive(:authorize) + expect(admin).to receive(:hub_label).with('github.com').and_return('github.com') + expect(Zenflow).to receive(:Log).with("Authorizing github.com") + expect(Zenflow::Github::CURRENT).to receive(:authorize) admin.authorize end end diff --git a/spec/zenflow/commands/deploy_spec.rb b/spec/zenflow/commands/deploy_spec.rb index 801cdfe..3dbd347 100644 --- a/spec/zenflow/commands/deploy_spec.rb +++ b/spec/zenflow/commands/deploy_spec.rb @@ -5,18 +5,18 @@ describe "Zenflow.Deploy" do context 'with migrations' do it 'deploys with migrations' do - Zenflow::Branch.should_receive(:push).with('some-server') - Zenflow.should_receive(:Log).with("Deploying with migrations to some-server") - Zenflow::Shell.should_receive(:run).with("cap some-server deploy:migrations") + expect(Zenflow::Branch).to receive(:push).with('some-server') + expect(Zenflow).to receive(:Log).with("Deploying with migrations to some-server") + expect(Zenflow::Shell).to receive(:run).with("cap some-server deploy:migrations") Zenflow::Deploy('some-server', :migrations => true) end end context 'without migrations' do it 'deploys without migrations' do - Zenflow::Branch.should_receive(:push).with('some-server') - Zenflow.should_receive(:Log).with("Deploying to some-server") - Zenflow::Shell.should_receive(:run).with("cap some-server deploy") + expect(Zenflow::Branch).to receive(:push).with('some-server') + expect(Zenflow).to receive(:Log).with("Deploying to some-server") + expect(Zenflow::Shell).to receive(:run).with("cap some-server deploy") Zenflow::Deploy('some-server') end end @@ -26,21 +26,21 @@ describe '#qa' do it 'Deploys to QA' do - Zenflow.should_receive(:Deploy).with('qa', {}) + expect(Zenflow).to receive(:Deploy).with('qa', {}) subject.qa end end describe '#staging' do it 'Deploys to staging' do - Zenflow.should_receive(:Deploy).with('staging', {}) + expect(Zenflow).to receive(:Deploy).with('staging', {}) subject.staging end end describe '#staging' do it 'Deploys to production' do - Zenflow.should_receive(:Deploy).with('production', {}) + expect(Zenflow).to receive(:Deploy).with('production', {}) subject.production end end diff --git a/spec/zenflow/commands/hotfix_spec.rb b/spec/zenflow/commands/hotfix_spec.rb index 2b8780a..1a277d5 100644 --- a/spec/zenflow/commands/hotfix_spec.rb +++ b/spec/zenflow/commands/hotfix_spec.rb @@ -5,11 +5,11 @@ subject { Zenflow::Hotfix.new } it { expect(subject.flow).to eq("hotfix") } - it { expect(subject.branch(:source)).to be_false } + it { expect(subject.branch(:source)).to be_falsey } it { expect(subject.branch(:deploy)).to match_array(["staging", "qa"]) } it { expect(subject.branch(:secondary_destination)).to eq("master") } it { expect(subject.changelog).to eq(:rotate) } it { expect(subject.version).to eq(:patch) } - it { expect(subject.tag).to be_true } + it { expect(subject.tag).to be true } end diff --git a/spec/zenflow/commands/release_spec.rb b/spec/zenflow/commands/release_spec.rb index 651ca0a..64eef44 100644 --- a/spec/zenflow/commands/release_spec.rb +++ b/spec/zenflow/commands/release_spec.rb @@ -6,10 +6,10 @@ it { expect(subject.flow).to eq("release") } it { expect(subject.branch(:source)).to eq("master") } - it { expect(subject.branch(:destination)).to be_false } + it { expect(subject.branch(:destination)).to be_falsey } it { expect(subject.branch(:deploy)).to match_array(["staging", "qa"]) } it { expect(subject.changelog).to eq(:rotate) } it { expect(subject.version).to eq(:minor) } - it { expect(subject.tag).to be_true } + it { expect(subject.tag).to be true } end diff --git a/spec/zenflow/commands/reviews_spec.rb b/spec/zenflow/commands/reviews_spec.rb index f94a3b0..d1ea624 100644 --- a/spec/zenflow/commands/reviews_spec.rb +++ b/spec/zenflow/commands/reviews_spec.rb @@ -5,9 +5,9 @@ describe "#list" do before do pull = double - pull.stub(:[]).with("number").and_return(1) - pull.stub(:[]).with("head").and_return({ "ref" => "URL" }) - Zenflow::PullRequest.should_receive(:list).and_return([pull]) + allow(pull).to receive(:[]).with("number").and_return(1) + allow(pull).to receive(:[]).with("head").and_return({ "ref" => "URL" }) + expect(Zenflow::PullRequest).to receive(:list).and_return([pull]) end it { capture(:stdout) { Zenflow::Reviews.new.invoke(:list) } } end diff --git a/spec/zenflow/helpers/ask_spec.rb b/spec/zenflow/helpers/ask_spec.rb index 4c00306..07063d9 100644 --- a/spec/zenflow/helpers/ask_spec.rb +++ b/spec/zenflow/helpers/ask_spec.rb @@ -4,35 +4,36 @@ describe "prompt" do before do - Zenflow.stub(:LogToFile) - $stdin.stub(:gets).and_return("good") + allow(Zenflow).to receive(:LogToFile) + allow($stdin).to receive(:gets).and_return("good") end it "displays a prompt" do - Zenflow::Query.should_receive(:print).with(">> How are you? ") + allow(Zenflow::Query).to receive(:print).with(">> How are you? ") Zenflow::Ask("How are you?") end it "displays a prompt with options" do - Zenflow::Query.should_receive(:print).with(">> How are you? [good/bad] ") + allow(Zenflow::Query).to receive(:print).with(">> How are you? [good/bad] ") Zenflow::Ask("How are you?", options: ["good", "bad"]) end it "displays a prompt with default" do - Zenflow::Query.should_receive(:print).with(">> How are you? [good] ") + allow(Zenflow::Query).to receive(:print).with(">> How are you? [good] ") Zenflow::Ask("How are you?", default: "good") end it "displays a prompt with options and default" do - Zenflow::Query.should_receive(:print).with(">> How are you? [good/bad] ") + allow(Zenflow::Query).to receive(:print).with(">> How are you? [good/bad] ") Zenflow::Ask("How are you?", options: ["good", "bad"], default: "good") end context "on error" do before(:each) do - Zenflow::Query.should_receive(:ask_question).at_least(:once).and_return('foo') - Zenflow::Query.should_receive(:handle_response).once.and_raise('something failed') - $stdout.should_receive(:puts).once + expect(Zenflow::Query).to receive(:ask_question).at_least(:once).and_return('foo') + expect(Zenflow::Query).to receive(:handle_response).once.and_raise('something failed') + allow($stdin).to receive(:gets).and_return('n') # Accounting for retry mechanic + expect($stdout).to receive(:puts).twice # With Retry there is a new puts end it{expect{Zenflow::Ask('howdy', response: 'foo', error_message: 'something failed')}.to raise_error(/something failed/)} @@ -40,10 +41,10 @@ context "on interrupt" do before(:each) do - Zenflow::Query.should_receive(:ask_question).once.and_return('foo') - Zenflow::Query.should_receive(:handle_response).once.and_raise(Interrupt) - Zenflow.should_receive(:LogToFile) - $stdout.should_receive(:puts).at_least(:once) + allow(Zenflow::Query).to receive(:ask_question).once.and_return('foo') + expect(Zenflow::Query).to receive(:handle_response).once.and_raise(Interrupt) + expect(Zenflow).to receive(:LogToFile) + allow($stdout).to receive(:puts).at_least(:once) end it{expect{Zenflow::Ask('howdy')}.to raise_error(SystemExit)} @@ -60,7 +61,7 @@ context 'with a response' do before(:each) do - Zenflow::Query.should_receive(:prompt_for_answer).with('foo?',{}).and_return('bar') + expect(Zenflow::Query).to receive(:prompt_for_answer).with('foo?',{}).and_return('bar') end it{expect(Zenflow::Query.ask_question('foo?')).to eq('bar')} @@ -69,8 +70,8 @@ describe '.prompt_for_answer' do before(:each) do - Zenflow::Query.should_receive(:print).with(">> Hi? [yes/bye] ") - STDIN.should_receive(:gets).and_return("bye") + expect(Zenflow::Query).to receive(:print).with(">> Hi? [yes/bye] ") + allow(STDIN).to receive(:gets).and_return("bye") end it{expect( @@ -82,12 +83,12 @@ describe '.handle_response' do context 'invalid response' do - before(:each){Zenflow::Query.should_receive(:valid_response?).and_return(false)} - it{expect{Zenflow::Query.handle_response('foo')}.to raise_error} + before(:each){expect(Zenflow::Query).to receive(:valid_response?).and_return(false)} + it{expect{Zenflow::Query.handle_response('foo')}.to raise_error(/is not a valid response/)} end context 'valid response' do - before(:each){Zenflow::Query.should_receive(:valid_response?).and_return(true)} + before(:each){expect(Zenflow::Query).to receive(:valid_response?).and_return(true)} it{expect(Zenflow::Query.handle_response('foo')).to eq('foo')} it{expect(Zenflow::Query.handle_response('Y')).to eq('y')} it{expect(Zenflow::Query.handle_response('N')).to eq('n')} diff --git a/spec/zenflow/helpers/branch_command_spec.rb b/spec/zenflow/helpers/branch_command_spec.rb index 0782a5a..8222780 100644 --- a/spec/zenflow/helpers/branch_command_spec.rb +++ b/spec/zenflow/helpers/branch_command_spec.rb @@ -16,9 +16,9 @@ class TestCommand < Zenflow::BranchCommand describe "Zenflow::BranchCommand" do describe "#branches" do before do - Zenflow.should_receive(:Log).with("Available test branches:") - Zenflow::Branch.should_receive(:list).with("test").and_return(["YES"]) - Zenflow.should_receive(:Log).with("* YES", indent: true, color: false) + expect(Zenflow).to receive(:Log).with("Available test branches:") + expect(Zenflow::Branch).to receive(:list).with("test").and_return(["YES"]) + expect(Zenflow).to receive(:Log).with("* YES", indent: true, color: false) end it { TestCommand.new.invoke(:branches) } end @@ -27,23 +27,23 @@ class TestCommand < Zenflow::BranchCommand context "when online" do context 'merge_strategy: merge' do before do - Zenflow.should_receive(:Ask).and_return("new-test-branch") - Zenflow::Branch.should_receive(:update).with("master") - Zenflow::Branch.should_receive(:create).with("test/new-test-branch", "master") - Zenflow::Branch.should_receive(:push).with("test/new-test-branch") - Zenflow::Branch.should_receive(:track).with("test/new-test-branch") + expect(Zenflow).to receive(:Ask).and_return("new-test-branch") + expect(Zenflow::Branch).to receive(:update).with("master") + expect(Zenflow::Branch).to receive(:create).with("test/new-test-branch", "master") + expect(Zenflow::Branch).to receive(:push).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:track).with("test/new-test-branch") end it { TestCommand.new.invoke(:start) } end context 'merge_strategy: rebase' do before do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('rebase') - Zenflow.should_receive(:Ask).and_return("new-test-branch") - Zenflow::Branch.should_receive(:update).with("master") - Zenflow::Branch.should_receive(:create).with("test/new-test-branch", "master") - Zenflow::Branch.should_not_receive(:push).with("test/new-test-branch") - Zenflow::Branch.should_not_receive(:track).with("test/new-test-branch") + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('rebase') + expect(Zenflow).to receive(:Ask).and_return("new-test-branch") + expect(Zenflow::Branch).to receive(:update).with("master") + expect(Zenflow::Branch).to receive(:create).with("test/new-test-branch", "master") + expect(Zenflow::Branch).to_not receive(:push).with("test/new-test-branch") + expect(Zenflow::Branch).to_not receive(:track).with("test/new-test-branch") end it { TestCommand.new.invoke(:start) } end @@ -51,30 +51,30 @@ class TestCommand < Zenflow::BranchCommand context "when offline" do before do - Zenflow.should_receive(:Ask).and_return("new-test-branch") - Zenflow::Branch.should_receive(:checkout).with("master") - Zenflow::Branch.should_receive(:create).with("test/new-test-branch", "master") + expect(Zenflow).to receive(:Ask).and_return("new-test-branch") + expect(Zenflow::Branch).to receive(:checkout).with("master") + expect(Zenflow::Branch).to receive(:create).with("test/new-test-branch", "master") end it { TestCommand.new.invoke(:start, nil, offline: true) } end context "when supplying a name" do before do - Zenflow::Branch.should_receive(:update).with("master") - Zenflow::Branch.should_receive(:create).with("test/new-test-branch", "master") - Zenflow::Branch.should_receive(:push).with("test/new-test-branch") - Zenflow::Branch.should_receive(:track).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:update).with("master") + expect(Zenflow::Branch).to receive(:create).with("test/new-test-branch", "master") + expect(Zenflow::Branch).to receive(:push).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:track).with("test/new-test-branch") end it { TestCommand.new.invoke(:start, ["new-test-branch"]) } end context "when asking for a name" do before do - $stdin.should_receive(:gets).and_return("new-test-branch\n") - Zenflow::Branch.should_receive(:update).with("master") - Zenflow::Branch.should_receive(:create).with("test/new-test-branch", "master") - Zenflow::Branch.should_receive(:push).with("test/new-test-branch") - Zenflow::Branch.should_receive(:track).with("test/new-test-branch") + expect($stdin).to receive(:gets).and_return("new-test-branch\n") + expect(Zenflow::Branch).to receive(:update).with("master") + expect(Zenflow::Branch).to receive(:create).with("test/new-test-branch", "master") + expect(Zenflow::Branch).to receive(:push).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:track).with("test/new-test-branch") end it { expect(capture(:stdout){ TestCommand.new.invoke(:start) }).to eq(">> Name of the test: ") } end @@ -83,37 +83,37 @@ class TestCommand < Zenflow::BranchCommand describe "#deploy" do context "when a project is not deployable" do before do - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow::Config.should_receive(:[]).with(:deployable).and_return(false) - Zenflow.should_receive(:Log).with("This project is not deployable right now", color: :red) + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::Config).to receive(:[]).with(:deployable).and_return(false) + expect(Zenflow).to receive(:Log).with("This project is not deployable right now", color: :red) end it { expect{TestCommand.new.invoke(:deploy)}.to raise_error(SystemExit) } end context "without running migrations" do before do - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow::Config.should_receive(:[]).with(:deployable).and_return(true) - Zenflow::Branch.should_receive(:update).with("deploy1") - Zenflow::Branch.should_receive(:update).with("deploy2") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch").twice - Zenflow.should_receive(:Deploy).with("deploy1", {}) - Zenflow.should_receive(:Deploy).with("deploy2", {}) - Zenflow::Branch.should_receive(:checkout).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::Config).to receive(:[]).with(:deployable).and_return(true) + expect(Zenflow::Branch).to receive(:update).with("deploy1") + expect(Zenflow::Branch).to receive(:update).with("deploy2") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch").twice + expect(Zenflow).to receive(:Deploy).with("deploy1", {}) + expect(Zenflow).to receive(:Deploy).with("deploy2", {}) + expect(Zenflow::Branch).to receive(:checkout).with("test/new-test-branch") end it { TestCommand.new.invoke(:deploy) } end context "when running migrations" do before do - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow::Config.should_receive(:[]).with(:deployable).and_return(true) - Zenflow::Branch.should_receive(:update).with("deploy1") - Zenflow::Branch.should_receive(:update).with("deploy2") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch").twice - Zenflow.should_receive(:Deploy).with("deploy1", { "migrations" => true }) - Zenflow.should_receive(:Deploy).with("deploy2", { "migrations" => true }) - Zenflow::Branch.should_receive(:checkout).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::Config).to receive(:[]).with(:deployable).and_return(true) + expect(Zenflow::Branch).to receive(:update).with("deploy1") + expect(Zenflow::Branch).to receive(:update).with("deploy2") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch").twice + expect(Zenflow).to receive(:Deploy).with("deploy1", { "migrations" => true }) + expect(Zenflow).to receive(:Deploy).with("deploy2", { "migrations" => true }) + expect(Zenflow::Branch).to receive(:checkout).with("test/new-test-branch") end it { TestCommand.new.invoke(:deploy, [], "migrations" => true) } end @@ -122,18 +122,18 @@ class TestCommand < Zenflow::BranchCommand describe "#update" do context "merge_strategy: merge" do before do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('merge') - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow::Branch.should_receive(:checkout).with("test/new-test-branch") - Zenflow::Branch.should_receive(:merge).with("master") + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('merge') + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::Branch).to receive(:checkout).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:merge).with("master") context "no override for --rebase" do - Zenflow::Branch.should_receive(:update).with("master", nil) + expect(Zenflow::Branch).to receive(:update).with("master", nil) it { TestCommand.new.invoke(:update) } end context "override for --rebase" do - Zenflow::Branch.should_receive(:update).with("master", true) + expect(Zenflow::Branch).to receive(:update).with("master", true) it { TestCommand.new.invoke(:update, true) } end end @@ -141,10 +141,10 @@ class TestCommand < Zenflow::BranchCommand context "merge_strategy: rebase" do before do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('rebase') - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow::Branch.should_receive(:update).with("master", nil) - Zenflow::Branch.should_receive(:rebase).with("test/new-test-branch", 'master') + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('rebase') + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::Branch).to receive(:update).with("master", nil) + expect(Zenflow::Branch).to receive(:rebase).with("test/new-test-branch", 'master') end it { TestCommand.new.invoke(:update) } end @@ -152,18 +152,18 @@ class TestCommand < Zenflow::BranchCommand describe "#diff" do before do - Zenflow.should_receive(:Log).with("Displaying diff with master") - Zenflow::Shell.should_receive(:[]).with("git difftool master") + expect(Zenflow).to receive(:Log).with("Displaying diff with master") + expect(Zenflow::Shell).to receive(:[]).with("git difftool master") end it { TestCommand.new.invoke(:diff) } end describe "#compare" do before do - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow.should_receive(:Log).with("Opening GitHub compare view for master...test/new-test-branch") - Zenflow::Repo.should_receive(:slug).and_return("test-repo") - Zenflow::Shell.should_receive(:[]).with("open https://github.com/test-repo/compare/master...test/new-test-branch") + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow).to receive(:Log).with("Opening GitHub compare view for master...test/new-test-branch") + expect(Zenflow::Repo).to receive(:slug).and_return("test-repo") + expect(Zenflow::Shell).to receive(:[]).with("open https://github.com/test-repo/compare/master...test/new-test-branch") end it { TestCommand.new.invoke(:compare) } end @@ -171,34 +171,34 @@ class TestCommand < Zenflow::BranchCommand describe "#review" do context "when pull request is found" do before do - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow::PullRequest.should_receive(:find_by_ref).with("test/new-test-branch").and_return({ html_url: "URL"}) - Zenflow.should_receive(:Log).with("A pull request for test/new-test-branch already exists", color: :red) - Zenflow.should_receive(:Log).with("URL", indent: true, color: false) + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::PullRequest).to receive(:find_by_ref).with("test/new-test-branch").and_return({ html_url: "URL"}) + expect(Zenflow).to receive(:Log).with("A pull request for test/new-test-branch already exists", color: :red) + expect(Zenflow).to receive(:Log).with("URL", indent: true, color: false) end it { expect{TestCommand.new.invoke(:review)}.to raise_error(SystemExit) } end context "with new pull request" do before do - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow::PullRequest.should_receive(:find_by_ref).with("test/new-test-branch").and_return(false) + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::PullRequest).to receive(:find_by_ref).with("test/new-test-branch").and_return(false) end context "with valid request" do before do - Zenflow.should_receive(:Ask).with("Describe this test:", required: true).and_return("A great test") + expect(Zenflow).to receive(:Ask).with("Describe this test:", required: true).and_return("A great test") pull = double(valid?: true) - pull.stub(:[]).with("html_url").and_return("URL") - Zenflow::PullRequest.should_receive(:create).with( + allow(pull).to receive(:[]).with("html_url").and_return("URL") + expect(Zenflow::PullRequest).to receive(:create).with( base: "production", head: "test/new-test-branch", title: "test: new-test-branch", body: "A great test" ).and_return(pull) - Zenflow.should_receive(:Log).with("Pull request was created!") - Zenflow.should_receive(:Log).with("URL", indent: true, color: false) - Zenflow::Shell.should_receive(:[]).with("open URL") + expect(Zenflow).to receive(:Log).with("Pull request was created!") + expect(Zenflow).to receive(:Log).with("URL", indent: true, color: false) + expect(Zenflow::Shell).to receive(:[]).with("open URL") end it { TestCommand.new.invoke(:review) } end @@ -207,33 +207,33 @@ class TestCommand < Zenflow::BranchCommand let(:pull){ double(valid?: false) } before do - Zenflow.should_receive(:Ask).with("Describe this test:", required: true).and_return("A great test") - Zenflow::PullRequest.should_receive(:create).with( + expect(Zenflow).to receive(:Ask).with("Describe this test:", required: true).and_return("A great test") + expect(Zenflow::PullRequest).to receive(:create).with( base: "production", head: "test/new-test-branch", title: "test: new-test-branch", body: "A great test" ).and_return(pull) - Zenflow.should_receive(:Log).with("There was a problem creating the pull request:", color: :red) + expect(Zenflow).to receive(:Log).with("There was a problem creating the pull request:", color: :red) end it "displays errors" do - pull.stub(:[]).with("errors").and_return([{"message" => "ERROR"},{"message" => "ERROR"}]) - Zenflow.should_receive(:Log).with("* ERROR", indent: true, color: :red).twice + allow(pull).to receive(:[]).with("errors").and_return([{"message" => "ERROR"},{"message" => "ERROR"}]) + expect(Zenflow).to receive(:Log).with("* ERROR", indent: true, color: :red).twice TestCommand.new.invoke(:review) end it "displays an error message" do - pull.stub(:[]).with("errors") - pull.stub(:[]).with("message").and_return("ERROR") - Zenflow.should_receive(:Log).with("* ERROR", indent: true, color: :red) + allow(pull).to receive(:[]).with("errors") + allow(pull).to receive(:[]).with("message").and_return("ERROR") + expect(Zenflow).to receive(:Log).with("* ERROR", indent: true, color: :red) TestCommand.new.invoke(:review) end it "handles unexpected failure" do - pull.stub(:[]).with("errors") - pull.stub(:[]).with("message") - Zenflow.should_receive(:Log).with(" * unexpected failure, both 'errors' and 'message' were empty in the response") + allow(pull).to receive(:[]).with("errors") + allow(pull).to receive(:[]).with("message") + expect(Zenflow).to receive(:Log).with(" * unexpected failure, both 'errors' and 'message' were empty in the response") TestCommand.new.invoke(:review) end end @@ -243,21 +243,21 @@ class TestCommand < Zenflow::BranchCommand describe "#abort" do let(:branch_name){"test/new-test-branch"} before { - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow::Branch.should_receive(:checkout).with("master") + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::Branch).to receive(:checkout).with("master") } context "when online" do before do - Zenflow::Branch.should_receive(:delete_remote).with(branch_name) - Zenflow::Branch.should_receive(:delete_local).with(branch_name, force: true) + expect(Zenflow::Branch).to receive(:delete_remote).with(branch_name) + expect(Zenflow::Branch).to receive(:delete_local).with(branch_name, force: true) end it { TestCommand.new.invoke(:abort) } end context "when offline" do before do - Zenflow::Branch.should_receive(:delete_local).with(branch_name, force: true) + expect(Zenflow::Branch).to receive(:delete_local).with(branch_name, force: true) end it { TestCommand.new.invoke(:abort, [], offline: true) } end @@ -265,81 +265,81 @@ class TestCommand < Zenflow::BranchCommand describe "#finish" do before do - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") end context "with confirmations" do it "without deployment to staging" do - Zenflow::Config.should_receive(:[]).with(:confirm_staging).and_return(true) - Zenflow.should_receive(:Ask).with("Has this been tested in a staging environment first?", options: ["Y", "n"], default: "y").and_return("n") - Zenflow.should_receive(:Log).with("Sorry, deploy to a staging environment first", color: :red) + expect(Zenflow::Config).to receive(:[]).with(:confirm_staging).and_return(true) + expect(Zenflow).to receive(:Ask).with("Has this been tested in a staging environment first?", options: ["Y", "n"], default: "y").and_return("n") + expect(Zenflow).to receive(:Log).with("Sorry, deploy to a staging environment first", color: :red) expect{TestCommand.new.invoke(:finish)}.to raise_error(SystemExit) end it "without review" do - Zenflow::Config.should_receive(:[]).with(:confirm_staging).and_return(true) - Zenflow::Config.should_receive(:[]).with(:confirm_review).and_return(true) - Zenflow.should_receive(:Ask).with("Has this been tested in a staging environment first?", options: ["Y", "n"], default: "y").and_return("y") - Zenflow.should_receive(:Ask).with("Has this been code reviewed yet?", options: ["Y", "n"], default: "y").and_return("n") - Zenflow.should_receive(:Log).with("Please have someone look at this first", color: :red) + expect(Zenflow::Config).to receive(:[]).with(:confirm_staging).and_return(true) + expect(Zenflow::Config).to receive(:[]).with(:confirm_review).and_return(true) + expect(Zenflow).to receive(:Ask).with("Has this been tested in a staging environment first?", options: ["Y", "n"], default: "y").and_return("y") + expect(Zenflow).to receive(:Ask).with("Has this been code reviewed yet?", options: ["Y", "n"], default: "y").and_return("n") + expect(Zenflow).to receive(:Log).with("Please have someone look at this first", color: :red) expect{TestCommand.new.invoke(:finish)}.to raise_error(SystemExit) end end context "without confirmations" do before do - Zenflow::Config.should_receive(:[]).with(:confirm_staging).and_return(false) - Zenflow::Config.should_receive(:[]).with(:confirm_review).and_return(false) + expect(Zenflow::Config).to receive(:[]).with(:confirm_staging).and_return(false) + expect(Zenflow::Config).to receive(:[]).with(:confirm_review).and_return(false) end context "with a merge_strategy of 'merge'" do before do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('merge') + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('merge') end context "when online" do before do - Zenflow::Branch.should_receive(:update).with("production") - Zenflow::Branch.should_receive(:checkout).with("test/new-test-branch") - Zenflow::Branch.should_receive(:merge).with("production") + expect(Zenflow::Branch).to receive(:update).with("production") + expect(Zenflow::Branch).to receive(:checkout).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:merge).with("production") - Zenflow::Version.should_receive(:update).with(:patch) + expect(Zenflow::Version).to receive(:update).with(:patch) - Zenflow::Changelog.should_receive(:update).with(rotate: true, name: "new-test-branch").and_return("YES") + expect(Zenflow::Changelog).to receive(:update).with(rotate: true, name: "new-test-branch").and_return("YES") - Zenflow::Branch.should_receive(:checkout).with("master") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch") - Zenflow::Branch.should_receive(:push).with("master") - Zenflow::Branch.should_receive(:checkout).with("production") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch") - Zenflow::Branch.should_receive(:push).with("production") + expect(Zenflow::Branch).to receive(:checkout).with("master") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:push).with("master") + expect(Zenflow::Branch).to receive(:checkout).with("production") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:push).with("production") - Zenflow::Branch.should_receive(:tag).with(Zenflow::Version.current.to_s, "YES") - Zenflow::Branch.should_receive(:push_tags) + expect(Zenflow::Branch).to receive(:tag).with(Zenflow::Version.current.to_s, "YES") + expect(Zenflow::Branch).to receive(:push_tags) - Zenflow::Branch.should_receive(:delete_remote).with("test/new-test-branch") - Zenflow::Branch.should_receive(:delete_local).with("test/new-test-branch", force: true) + expect(Zenflow::Branch).to receive(:delete_remote).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:delete_local).with("test/new-test-branch", force: true) end it { TestCommand.new.invoke(:finish) } end context "when offline" do before do - Zenflow::Branch.should_receive(:checkout).with("test/new-test-branch") - Zenflow::Branch.should_receive(:merge).with("production") + expect(Zenflow::Branch).to receive(:checkout).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:merge).with("production") - Zenflow::Version.should_receive(:update).with(:patch) + expect(Zenflow::Version).to receive(:update).with(:patch) - Zenflow::Changelog.should_receive(:update).with(rotate: true, name: "new-test-branch").and_return("YES") + expect(Zenflow::Changelog).to receive(:update).with(rotate: true, name: "new-test-branch").and_return("YES") - Zenflow::Branch.should_receive(:checkout).with("master") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch") - Zenflow::Branch.should_receive(:checkout).with("production") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:checkout).with("master") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:checkout).with("production") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch") - Zenflow::Branch.should_receive(:tag).with(Zenflow::Version.current.to_s, "YES") + expect(Zenflow::Branch).to receive(:tag).with(Zenflow::Version.current.to_s, "YES") - Zenflow::Branch.should_receive(:delete_local).with("test/new-test-branch", force: true) + expect(Zenflow::Branch).to receive(:delete_local).with("test/new-test-branch", force: true) end it { TestCommand.new.invoke(:finish, [], offline: true) } end @@ -347,50 +347,50 @@ class TestCommand < Zenflow::BranchCommand context "with a merge_strategy of 'rebase'" do before do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('rebase') + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('rebase') end context "when online" do before do - Zenflow::Branch.should_receive(:update).with("production") - Zenflow::Branch.should_receive(:rebase).with("test/new-test-branch", 'production') + expect(Zenflow::Branch).to receive(:update).with("production") + expect(Zenflow::Branch).to receive(:rebase).with("test/new-test-branch", 'production') - Zenflow::Version.should_receive(:update).with(:patch) + expect(Zenflow::Version).to receive(:update).with(:patch) - Zenflow::Changelog.should_receive(:update).with(rotate: true, name: "new-test-branch").and_return("YES") + expect(Zenflow::Changelog).to receive(:update).with(rotate: true, name: "new-test-branch").and_return("YES") - Zenflow::Branch.should_receive(:checkout).with("master") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch") - Zenflow::Branch.should_receive(:push).with("master") - Zenflow::Branch.should_receive(:checkout).with("production") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch") - Zenflow::Branch.should_receive(:push).with("production") + expect(Zenflow::Branch).to receive(:checkout).with("master") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:push).with("master") + expect(Zenflow::Branch).to receive(:checkout).with("production") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:push).with("production") - Zenflow::Branch.should_receive(:tag).with(Zenflow::Version.current.to_s, "YES") - Zenflow::Branch.should_receive(:push_tags) + expect(Zenflow::Branch).to receive(:tag).with(Zenflow::Version.current.to_s, "YES") + expect(Zenflow::Branch).to receive(:push_tags) - Zenflow::Branch.should_receive(:delete_remote).with("test/new-test-branch") - Zenflow::Branch.should_receive(:delete_local).with("test/new-test-branch", force: true) + expect(Zenflow::Branch).to receive(:delete_remote).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:delete_local).with("test/new-test-branch", force: true) end it { TestCommand.new.invoke(:finish) } end context "when offline" do before do - Zenflow::Branch.should_receive(:rebase).with("test/new-test-branch", 'production') + expect(Zenflow::Branch).to receive(:rebase).with("test/new-test-branch", 'production') - Zenflow::Version.should_receive(:update).with(:patch) + expect(Zenflow::Version).to receive(:update).with(:patch) - Zenflow::Changelog.should_receive(:update).with(rotate: true, name: "new-test-branch").and_return("YES") + expect(Zenflow::Changelog).to receive(:update).with(rotate: true, name: "new-test-branch").and_return("YES") - Zenflow::Branch.should_receive(:checkout).with("master") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch") - Zenflow::Branch.should_receive(:checkout).with("production") - Zenflow::Branch.should_receive(:merge).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:checkout).with("master") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:checkout).with("production") + expect(Zenflow::Branch).to receive(:merge).with("test/new-test-branch") - Zenflow::Branch.should_receive(:tag).with(Zenflow::Version.current.to_s, "YES") + expect(Zenflow::Branch).to receive(:tag).with(Zenflow::Version.current.to_s, "YES") - Zenflow::Branch.should_receive(:delete_local).with("test/new-test-branch", force: true) + expect(Zenflow::Branch).to receive(:delete_local).with("test/new-test-branch", force: true) end it { TestCommand.new.invoke(:finish, [], offline: true) } end @@ -400,9 +400,9 @@ class TestCommand < Zenflow::BranchCommand describe "#publish" do before do - Zenflow::Branch.should_receive(:current).with("test").and_return("new-test-branch") - Zenflow::Branch.should_receive(:push).with("test/new-test-branch") - Zenflow::Branch.should_receive(:track).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:current).with("test").and_return("new-test-branch") + expect(Zenflow::Branch).to receive(:push).with("test/new-test-branch") + expect(Zenflow::Branch).to receive(:track).with("test/new-test-branch") end it { TestCommand.new.invoke(:publish) } end diff --git a/spec/zenflow/helpers/branch_spec.rb b/spec/zenflow/helpers/branch_spec.rb index f43c6f9..593c023 100644 --- a/spec/zenflow/helpers/branch_spec.rb +++ b/spec/zenflow/helpers/branch_spec.rb @@ -4,7 +4,7 @@ describe 'self.list' do context "when the prefix has no branches" do before do - Zenflow::Shell.should_receive(:run).with("git branch | grep features", :silent => true).and_return("") + expect(Zenflow::Shell).to receive(:run).with("git branch | grep features", :silent => true).and_return("") end it "indicates there are no branches" do @@ -14,7 +14,7 @@ context "when the prefix has branches" do before do - Zenflow::Shell.should_receive(:run).with("git branch | grep features", :silent => true).and_return(" feature/test_zenflow\n* feature/refactor_zenflow\n") + expect(Zenflow::Shell).to receive(:run).with("git branch | grep features", :silent => true).and_return(" feature/test_zenflow\n* feature/refactor_zenflow\n") end it "indicates there are no branches" do @@ -26,7 +26,7 @@ describe "self.current" do context "when the current branch doesn't match the prefix" do before do - Zenflow::Shell.should_receive(:run).with("git branch | grep '* feature'", :silent => true).and_return("") + expect(Zenflow::Shell).to receive(:run).with("git branch | grep '* feature'", :silent => true).and_return("") end it "returns nil" do @@ -36,7 +36,7 @@ context "when the current branch matches the prefix" do before do - Zenflow::Shell.should_receive(:run).with("git branch | grep '* feature'", :silent => true).and_return("* feature/test-current-branch\n") + expect(Zenflow::Shell).to receive(:run).with("git branch | grep '* feature'", :silent => true).and_return("* feature/test-current-branch\n") end it "returns returns the branch name" do @@ -47,39 +47,39 @@ describe "self.update" do it "updates the branch" do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('merge') - Zenflow.should_receive(:Log).with("Updating the master branch") - Zenflow::Shell.should_receive(:run).with("git checkout master && git pull") + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('merge') + expect(Zenflow).to receive(:Log).with("Updating the master branch") + expect(Zenflow::Shell).to receive(:run).with("git checkout master && git pull") Zenflow::Branch.update('master') end it "updates the branch using a rebase override" do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('merge') - Zenflow.should_receive(:Log).with("Updating the master branch using pull with --rebase") - Zenflow::Shell.should_receive(:run).with("git checkout master && git pull --rebase") + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('merge') + expect(Zenflow).to receive(:Log).with("Updating the master branch using pull with --rebase") + expect(Zenflow::Shell).to receive(:run).with("git checkout master && git pull --rebase") Zenflow::Branch.update('master', true) end end describe "self.apply_merge_strategy" do it "merges the branch using the merge strategy" do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('merge') - Zenflow::Branch.should_receive(:checkout).with("feature/testing-123") - Zenflow::Branch.should_receive(:merge).with('master') + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('merge') + expect(Zenflow::Branch).to receive(:checkout).with("feature/testing-123") + expect(Zenflow::Branch).to receive(:merge).with('master') Zenflow::Branch.apply_merge_strategy('feature', 'testing-123', 'master') end it "merges the branch using the rebase strategy" do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('rebase') - Zenflow::Branch.should_receive(:rebase).with("feature/testing-123", 'master') + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('rebase') + expect(Zenflow::Branch).to receive(:rebase).with("feature/testing-123", 'master') Zenflow::Branch.apply_merge_strategy('feature', 'testing-123', 'master') end it "optionally allows the merge strategy to be overridden by a --rebase flag when doing an update" do - Zenflow::Config.should_receive(:[]).with(:merge_strategy).and_return('merge') - Zenflow::Branch.should_receive(:rebase).with("feature/testing-123", 'master') + expect(Zenflow::Config).to receive(:[]).with(:merge_strategy).and_return('merge') + expect(Zenflow::Branch).to receive(:rebase).with("feature/testing-123", 'master') Zenflow::Branch.apply_merge_strategy('feature', 'testing-123', 'master', true) end @@ -87,8 +87,8 @@ describe "self.create" do it "updates the branch" do - Zenflow.should_receive(:Log).with("Creating the feature/test-branch-creation branch based on master") - Zenflow::Shell.should_receive(:run).with("git checkout -b feature/test-branch-creation master") + expect(Zenflow).to receive(:Log).with("Creating the feature/test-branch-creation branch based on master") + expect(Zenflow::Shell).to receive(:run).with("git checkout -b feature/test-branch-creation master") Zenflow::Branch.create('feature/test-branch-creation', 'master') end end @@ -105,26 +105,26 @@ end it 'pushes to the configured remote' do - Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to some-remote") - Zenflow::Shell.should_receive(:run).with("git push some-remote feature/test-pushing") + expect(Zenflow).to receive(:Log).with("Pushing the feature/test-pushing branch to some-remote") + expect(Zenflow::Shell).to receive(:run).with("git push some-remote feature/test-pushing") Zenflow::Branch.push('feature/test-pushing') end end context "when a remote is not configured" do it 'pushes to the origin' do - Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to origin") - Zenflow::Shell.should_receive(:run).with("git push origin feature/test-pushing") + expect(Zenflow).to receive(:Log).with("Pushing the feature/test-pushing branch to origin") + expect(Zenflow::Shell).to receive(:run).with("git push origin feature/test-pushing") Zenflow::Branch.push('feature/test-pushing') end end context "when a backup remote is not configured" do it "pushes to the primary remote and then pushes to the backup remote" do - Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to origin") - Zenflow::Shell.should_receive(:run).with("git push origin feature/test-pushing") - Zenflow.should_not_receive(:Log).with("Pushing the feature/test-pushing branch to backup-remote") - Zenflow::Shell.should_not_receive(:run).with("git push backup-remote feature/test-pushing") + expect(Zenflow).to receive(:Log).with("Pushing the feature/test-pushing branch to origin") + expect(Zenflow::Shell).to receive(:run).with("git push origin feature/test-pushing") + expect(Zenflow).to_not receive(:Log).with("Pushing the feature/test-pushing branch to backup-remote") + expect(Zenflow::Shell).to_not receive(:run).with("git push backup-remote feature/test-pushing") Zenflow::Branch.push('feature/test-pushing') end end @@ -135,10 +135,10 @@ end it "pushes to the primary remote and then pushes to the backup remote" do - Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to origin") - Zenflow::Shell.should_receive(:run).with("git push origin feature/test-pushing") - Zenflow.should_receive(:Log).with("Pushing the feature/test-pushing branch to backup-remote") - Zenflow::Shell.should_receive(:run).with("git push backup-remote feature/test-pushing") + expect(Zenflow).to receive(:Log).with("Pushing the feature/test-pushing branch to origin") + expect(Zenflow::Shell).to receive(:run).with("git push origin feature/test-pushing") + expect(Zenflow).to receive(:Log).with("Pushing the feature/test-pushing branch to backup-remote") + expect(Zenflow::Shell).to receive(:run).with("git push backup-remote feature/test-pushing") Zenflow::Branch.push('feature/test-pushing') end end @@ -156,26 +156,26 @@ end it 'pushes to the configured remote' do - Zenflow.should_receive(:Log).with("Pushing tags to some-remote") - Zenflow::Shell.should_receive(:run).with("git push some-remote --tags") + expect(Zenflow).to receive(:Log).with("Pushing tags to some-remote") + expect(Zenflow::Shell).to receive(:run).with("git push some-remote --tags") Zenflow::Branch.push_tags end end context "when a remote is not configured" do it 'pushes to the origin' do - Zenflow.should_receive(:Log).with("Pushing tags to origin") - Zenflow::Shell.should_receive(:run).with("git push origin --tags") + expect(Zenflow).to receive(:Log).with("Pushing tags to origin") + expect(Zenflow::Shell).to receive(:run).with("git push origin --tags") Zenflow::Branch.push_tags end end context "when a backup remote is not configured" do it "pushes to the primary remote and then pushes to the backup remote" do - Zenflow.should_receive(:Log).with("Pushing tags to origin") - Zenflow::Shell.should_receive(:run).with("git push origin --tags") - Zenflow.should_not_receive(:Log).with("Pushing tags to backup-remote") - Zenflow::Shell.should_not_receive(:run).with("git push backup-remote --tags") + expect(Zenflow).to receive(:Log).with("Pushing tags to origin") + expect(Zenflow::Shell).to receive(:run).with("git push origin --tags") + expect(Zenflow).to_not receive(:Log).with("Pushing tags to backup-remote") + expect(Zenflow::Shell).to_not receive(:run).with("git push backup-remote --tags") Zenflow::Branch.push_tags end end @@ -186,10 +186,10 @@ end it "pushes to the primary remote and then pushes to the backup remote" do - Zenflow.should_receive(:Log).with("Pushing tags to origin") - Zenflow::Shell.should_receive(:run).with("git push origin --tags") - Zenflow.should_receive(:Log).with("Pushing tags to backup-remote") - Zenflow::Shell.should_receive(:run).with("git push backup-remote --tags") + expect(Zenflow).to receive(:Log).with("Pushing tags to origin") + expect(Zenflow::Shell).to receive(:run).with("git push origin --tags") + expect(Zenflow).to receive(:Log).with("Pushing tags to backup-remote") + expect(Zenflow::Shell).to receive(:run).with("git push backup-remote --tags") Zenflow::Branch.push_tags end end @@ -206,8 +206,8 @@ end it "tracks the branch in that remote" do - Zenflow.should_receive(:Log).with("Tracking the feature/test-tracking branch against some-remote/feature/test-tracking") - Zenflow::Shell.should_receive(:run).with("git branch --set-upstream-to=some-remote/feature/test-tracking feature/test-tracking") + expect(Zenflow).to receive(:Log).with("Tracking the feature/test-tracking branch against some-remote/feature/test-tracking") + expect(Zenflow::Shell).to receive(:run).with("git branch --set-upstream-to=some-remote/feature/test-tracking feature/test-tracking") Zenflow::Branch.track('feature/test-tracking') end end @@ -218,8 +218,8 @@ end it "tracks the branch in origin" do - Zenflow.should_receive(:Log).with("Tracking the feature/test-tracking branch against origin/feature/test-tracking") - Zenflow::Shell.should_receive(:run).with("git branch --set-upstream-to=origin/feature/test-tracking feature/test-tracking") + expect(Zenflow).to receive(:Log).with("Tracking the feature/test-tracking branch against origin/feature/test-tracking") + expect(Zenflow::Shell).to receive(:run).with("git branch --set-upstream-to=origin/feature/test-tracking feature/test-tracking") Zenflow::Branch.track('feature/test-tracking') end end @@ -227,24 +227,24 @@ describe "self.checkout" do it "checks out the branch" do - Zenflow.should_receive(:Log).with("Switching to the feature/test-checkout branch") - Zenflow::Shell.should_receive(:run).with("git checkout feature/test-checkout") + expect(Zenflow).to receive(:Log).with("Switching to the feature/test-checkout branch") + expect(Zenflow::Shell).to receive(:run).with("git checkout feature/test-checkout") Zenflow::Branch.checkout('feature/test-checkout') end end describe "self.rebase" do it "checks out the branch" do - Zenflow.should_receive(:Log).with("Rebasing feature/test-checkout on top of the master branch") - Zenflow::Shell.should_receive(:run).with("git rebase master feature/test-checkout") + expect(Zenflow).to receive(:Log).with("Rebasing feature/test-checkout on top of the master branch") + expect(Zenflow::Shell).to receive(:run).with("git rebase master feature/test-checkout") Zenflow::Branch.rebase('feature/test-checkout', 'master') end end describe "self.merge" do it "merges in the specified branch" do - Zenflow.should_receive(:Log).with("Merging in the feature/test-merging branch") - Zenflow::Shell.should_receive(:run).with("git merge --no-ff feature/test-merging") + expect(Zenflow).to receive(:Log).with("Merging in the feature/test-merging branch") + expect(Zenflow::Shell).to receive(:run).with("git merge --no-ff feature/test-merging") Zenflow::Branch.merge('feature/test-merging') end end @@ -252,18 +252,18 @@ describe "self.tag" do context "when name and description are specified" do it "creates a tag with the name and description" do - Zenflow.should_receive(:Log).with("Tagging the release") - Zenflow::Shell.should_receive(:run).with("git tag -a 'v0.1.2' -m 'this tag is amazing'") + expect(Zenflow).to receive(:Log).with("Tagging the release") + expect(Zenflow::Shell).to receive(:run).with("git tag -a 'v0.1.2' -m 'this tag is amazing'") Zenflow::Branch.tag('v0.1.2', 'this tag is amazing') end end context "when name and description are not specified" do it "asks for name and description and then creates a tag" do - Zenflow.should_receive(:Log).with("Tagging the release") - Zenflow.should_receive(:Ask).with('Name of the tag:', :required => true).and_return('v0.1.3') - Zenflow.should_receive(:Ask).with('Tag message:', :required => true).and_return('this tag is even more amazing') - Zenflow::Shell.should_receive(:run).with("git tag -a 'v0.1.3' -m 'this tag is even more amazing'") + expect(Zenflow).to receive(:Log).with("Tagging the release") + expect(Zenflow).to receive(:Ask).with('Name of the tag:', :required => true).and_return('v0.1.3') + expect(Zenflow).to receive(:Ask).with('Tag message:', :required => true).and_return('this tag is even more amazing') + expect(Zenflow::Shell).to receive(:run).with("git tag -a 'v0.1.3' -m 'this tag is even more amazing'") Zenflow::Branch.tag end end @@ -281,26 +281,26 @@ end it 'pushes to the configured remote' do - Zenflow.should_receive(:Log).with("Removing the remote branch from some-remote") - Zenflow::Shell.should_receive(:run).with("git branch -r | grep some-remote/feature/test-remote-removal && git push some-remote :feature/test-remote-removal || echo ''") + expect(Zenflow).to receive(:Log).with("Removing the remote branch from some-remote") + expect(Zenflow::Shell).to receive(:run).with("git branch -r | grep some-remote/feature/test-remote-removal && git push some-remote :feature/test-remote-removal || echo ''") Zenflow::Branch.delete_remote('feature/test-remote-removal') end end context "when a remote is not configured" do it 'pushes to the origin' do - Zenflow.should_receive(:Log).with("Removing the remote branch from origin") - Zenflow::Shell.should_receive(:run).with("git branch -r | grep origin/feature/test-remote-removal && git push origin :feature/test-remote-removal || echo ''") + expect(Zenflow).to receive(:Log).with("Removing the remote branch from origin") + expect(Zenflow::Shell).to receive(:run).with("git branch -r | grep origin/feature/test-remote-removal && git push origin :feature/test-remote-removal || echo ''") Zenflow::Branch.delete_remote('feature/test-remote-removal') end end context "when a backup remote is not configured" do it "pushes to the primary remote and then pushes to the backup remote" do - Zenflow.should_receive(:Log).with("Removing the remote branch from origin") - Zenflow::Shell.should_receive(:run).with("git branch -r | grep origin/feature/test-remote-removal && git push origin :feature/test-remote-removal || echo ''") - Zenflow.should_not_receive(:Log).with(/Removing the remote branch/) - Zenflow::Shell.should_not_receive(:run).with(/git push/) + expect(Zenflow).to receive(:Log).with("Removing the remote branch from origin") + expect(Zenflow::Shell).to receive(:run).with("git branch -r | grep origin/feature/test-remote-removal && git push origin :feature/test-remote-removal || echo ''") + expect(Zenflow).to_not receive(:Log).with(/Removing the remote branch/) + expect(Zenflow::Shell).to_not receive(:run).with(/git push/) Zenflow::Branch.delete_remote('feature/test-remote-removal') end end @@ -311,10 +311,10 @@ end it "pushes to the primary remote and then pushes to the backup remote" do - Zenflow.should_receive(:Log).with("Removing the remote branch from origin") - Zenflow::Shell.should_receive(:run).with("git branch -r | grep origin/feature/test-remote-removal && git push origin :feature/test-remote-removal || echo ''") - Zenflow.should_receive(:Log).with("Removing the remote branch from backup-remote") - Zenflow::Shell.should_receive(:run).with("git branch -r | grep backup-remote/feature/test-remote-removal && git push backup-remote :feature/test-remote-removal || echo ''") + expect(Zenflow).to receive(:Log).with("Removing the remote branch from origin") + expect(Zenflow::Shell).to receive(:run).with("git branch -r | grep origin/feature/test-remote-removal && git push origin :feature/test-remote-removal || echo ''") + expect(Zenflow).to receive(:Log).with("Removing the remote branch from backup-remote") + expect(Zenflow::Shell).to receive(:run).with("git branch -r | grep backup-remote/feature/test-remote-removal && git push backup-remote :feature/test-remote-removal || echo ''") Zenflow::Branch.delete_remote('feature/test-remote-removal') end end @@ -323,16 +323,16 @@ describe "self.delete_local" do context "with the force option" do it "force deletes the local branch" do - Zenflow.should_receive(:Log).with("Removing the local branch") - Zenflow::Shell.should_receive(:run).with("git branch -D feature/test-local-deletion") + expect(Zenflow).to receive(:Log).with("Removing the local branch") + expect(Zenflow::Shell).to receive(:run).with("git branch -D feature/test-local-deletion") Zenflow::Branch.delete_local('feature/test-local-deletion', :force => true) end end context "without the force option" do it "deletes the local branch" do - Zenflow.should_receive(:Log).with("Removing the local branch") - Zenflow::Shell.should_receive(:run).with("git branch -d feature/test-local-deletion") + expect(Zenflow).to receive(:Log).with("Removing the local branch") + expect(Zenflow::Shell).to receive(:run).with("git branch -d feature/test-local-deletion") Zenflow::Branch.delete_local('feature/test-local-deletion') end end diff --git a/spec/zenflow/helpers/changelog_spec.rb b/spec/zenflow/helpers/changelog_spec.rb index 7e22301..1aa4120 100644 --- a/spec/zenflow/helpers/changelog_spec.rb +++ b/spec/zenflow/helpers/changelog_spec.rb @@ -4,38 +4,38 @@ describe '.update' do context "when no changelog exists" do - before { File.should_receive(:exist?).with("CHANGELOG.md").and_return(false) } + before { expect(File).to receive(:exist?).with("CHANGELOG.md").and_return(false) } it "does nothing" do - Zenflow::Changelog.should_not_receive(:prompt_for_change) + expect(Zenflow::Changelog).to_not receive(:prompt_for_change) expect(Zenflow::Changelog.update).to be_nil end end context "when the changelog exists" do - before { File.should_receive(:exist?).with("CHANGELOG.md").and_return(true) } + before { expect(File).to receive(:exist?).with("CHANGELOG.md").and_return(true) } context "when a change is received" do - before { Zenflow::Changelog.should_receive(:prompt_for_change).and_return('wrote tests for updating the changelog') } + before { expect(Zenflow::Changelog).to receive(:prompt_for_change).and_return('wrote tests for updating the changelog') } it "prepends the change to the changelog and returns the change" do - Zenflow::Changelog.should_receive(:prepend_change_to_changelog).with('* wrote tests for updating the changelog', {}) + expect(Zenflow::Changelog).to receive(:prepend_change_to_changelog).with('* wrote tests for updating the changelog', {}) expect(Zenflow::Changelog.update).to eq('wrote tests for updating the changelog') end end context "when no change is received" do - before { Zenflow::Changelog.should_receive(:prompt_for_change).and_return(nil) } + before { expect(Zenflow::Changelog).to receive(:prompt_for_change).and_return(nil) } context "and the rotate option is invoked" do it "rotates the changelog and returns nil" do - Zenflow::Changelog.should_receive(:rotate).with(:commit => true) + expect(Zenflow::Changelog).to receive(:rotate).with(:commit => true) expect(Zenflow::Changelog.update(:rotate => true)).to be_nil end end context "and the rotate option is absent" do it "rotates the changelog and returns nil" do - Zenflow::Changelog.should_not_receive(:rotate) + expect(Zenflow::Changelog).to_not receive(:rotate) expect(Zenflow::Changelog.update).to be_nil end end @@ -46,14 +46,14 @@ describe '.prompt_for_change' do context "when the required option is false" do it "asks for a change and indicates it is optional" do - Zenflow.should_receive(:Ask).with("Add one line to the changelog (optional):", :required => false) + expect(Zenflow).to receive(:Ask).with("Add one line to the changelog (optional):", :required => false) Zenflow::Changelog.prompt_for_change(:required => false) end end context "when the required option is anything else" do it "asks for a change and does not indicate is optional" do - Zenflow.should_receive(:Ask).with("Add one line to the changelog:", :required => true) + expect(Zenflow).to receive(:Ask).with("Add one line to the changelog:", :required => true) Zenflow::Changelog.prompt_for_change end end @@ -62,21 +62,21 @@ describe '.prepend_change_to_changelog' do context "when the rotate option is not invoked" do it "prepends changes to the changelog" do - Zenflow::Changelog.should_receive(:prepended_changelog).with('changed the world').and_return('some other text I suppose') + expect(Zenflow::Changelog).to receive(:prepended_changelog).with('changed the world').and_return('some other text I suppose') file_handler = double() - file_handler.should_receive(:write).with('some other text I suppose') - File.should_receive(:open).with("CHANGELOG.md", "w").and_yield(file_handler) - Zenflow::Changelog.should_not_receive(:rotate) - Zenflow::Shell.should_receive(:run).with("git add CHANGELOG.md && git commit -m 'Adding line to CHANGELOG: changed the world'") + expect(file_handler).to receive(:write).with('some other text I suppose') + expect(File).to receive(:open).with("CHANGELOG.md", "w").and_yield(file_handler) + expect(Zenflow::Changelog).to_not receive(:rotate) + expect(Zenflow::Shell).to receive(:run).with("git add CHANGELOG.md && git commit -m 'Adding line to CHANGELOG: changed the world'") Zenflow::Changelog.prepend_change_to_changelog('changed the world') end end context "when the rotate option is present" do it "prepends changes to the changelog" do - File.should_receive(:open).with("CHANGELOG.md", "w") - Zenflow::Changelog.should_receive(:rotate) - Zenflow::Shell.should_receive(:run).with("git add CHANGELOG.md && git commit -m 'Adding line to CHANGELOG: changed the world'") + expect(File).to receive(:open).with("CHANGELOG.md", "w") + expect(Zenflow::Changelog).to receive(:rotate) + expect(Zenflow::Shell).to receive(:run).with("git add CHANGELOG.md && git commit -m 'Adding line to CHANGELOG: changed the world'") Zenflow::Changelog.prepend_change_to_changelog('changed the world', :rotate => true) end end @@ -84,44 +84,44 @@ describe '.prepended_changelog' do it "returns the new changes prepended to the existing changelog" do - Zenflow::Changelog.should_receive(:get_changes).and_return(['test branching', 'amongst other things']) + expect(Zenflow::Changelog).to receive(:get_changes).and_return(['test branching', 'amongst other things']) expect(Zenflow::Changelog.prepended_changelog('test prepended changelog')).to eq("test prepended changelog\ntest branching\namongst other things\n") end end describe '.rotate' do context "when there are no changes to rotate" do - before { Zenflow::Changelog.should_receive(:rotated_changelog).and_return(nil) } + before { expect(Zenflow::Changelog).to receive(:rotated_changelog).and_return(nil) } it "does nothing" do - File.should_not_receive(:open) + expect(File).to_not receive(:open) Zenflow::Changelog.rotate end end context "when there are no changes to rotate" do - before { Zenflow::Changelog.should_receive(:rotated_changelog).and_return('amazing new changelog') } + before { expect(Zenflow::Changelog).to receive(:rotated_changelog).and_return('amazing new changelog') } context "when the commit option is not invoked" do it "rotates the changelog but does not create a commit" do - Zenflow::Version.should_receive(:current) - Zenflow.should_receive(:Log) + expect(Zenflow::Version).to receive(:current) + expect(Zenflow).to receive(:Log) file_handler = double() - file_handler.should_receive(:write).with('amazing new changelog') - File.should_receive(:open).with("CHANGELOG.md", "w").and_yield(file_handler) - Zenflow::Shell.should_not_receive(:run) + expect(file_handler).to receive(:write).with('amazing new changelog') + expect(File).to receive(:open).with("CHANGELOG.md", "w").and_yield(file_handler) + expect(Zenflow::Shell).to_not receive(:run) Zenflow::Changelog.rotate end end context "when the commit option is present" do it "rotates the changelog and creates a commit" do - Zenflow::Version.should_receive(:current) - Zenflow.should_receive(:Log) + expect(Zenflow::Version).to receive(:current) + expect(Zenflow).to receive(:Log) file_handler = double() - file_handler.should_receive(:write).with('amazing new changelog') - File.should_receive(:open).with("CHANGELOG.md", "w").and_yield(file_handler) - Zenflow::Shell.should_receive(:run).with("git add CHANGELOG.md && git commit -m 'Rotating CHANGELOG.'") + expect(file_handler).to receive(:write).with('amazing new changelog') + expect(File).to receive(:open).with("CHANGELOG.md", "w").and_yield(file_handler) + expect(Zenflow::Shell).to receive(:run).with("git add CHANGELOG.md && git commit -m 'Rotating CHANGELOG.'") Zenflow::Changelog.rotate(:commit => true) end end @@ -130,7 +130,7 @@ describe '.rotated_changelog' do it "returns the changelog with changes rotated to the bottom" do - Zenflow::Changelog.should_receive(:get_changes).and_return(['test branching', 'amongst other things']) + expect(Zenflow::Changelog).to receive(:get_changes).and_return(['test branching', 'amongst other things']) expect(Zenflow::Changelog.rotated_changelog).to match(/amongst other things\n\n---- #{Zenflow::Version.current.to_s} \/ #{Time.now.strftime('%Y-%m-%d')} [-]+\ntest branching\n/) end end @@ -138,24 +138,24 @@ describe '.get_changes' do context "when the changelog file doesn't exist" do before do - Zenflow::Changelog.should_receive(:exist?).and_return(false) + expect(Zenflow::Changelog).to receive(:exist?).and_return(false) end it 'does nothing' do - File.should_not_receive(:read) + expect(File).to_not receive(:read) expect(Zenflow::Changelog.get_changes).to be_nil end end context "when the changelog exists" do before do - Zenflow::Changelog.should_receive(:exist?).and_return(true) + expect(Zenflow::Changelog).to receive(:exist?).and_return(true) end context "but there are no changes" do before do @file = "\n--------------------------------------------------------------------------------\nold changes" - File.should_receive(:read).with('CHANGELOG.md').and_return(@file) + expect(File).to receive(:read).with('CHANGELOG.md').and_return(@file) end it 'returns the no new changes, but include old changes' do @@ -166,7 +166,7 @@ context "and there are changes" do before do file = "new changes\n--------------------------------------------------------------------------------\nold changes" - File.should_receive(:read).with('CHANGELOG.md').and_return(file) + expect(File).to receive(:read).with('CHANGELOG.md').and_return(file) end it "returns the new changes and the rest of the changelog" do @@ -179,8 +179,8 @@ describe '.create' do it "writes the changelog template to the changelog" do file = double() - file.should_receive(:write).with(Zenflow::Changelog.changelog_template) - File.should_receive(:open).with('CHANGELOG.md', 'w').and_yield(file) + expect(file).to receive(:write).with(Zenflow::Changelog.changelog_template) + expect(File).to receive(:open).with('CHANGELOG.md', 'w').and_yield(file) Zenflow::Changelog.create end end diff --git a/spec/zenflow/helpers/github_spec.rb b/spec/zenflow/helpers/github_spec.rb index b6b77c1..db6865f 100644 --- a/spec/zenflow/helpers/github_spec.rb +++ b/spec/zenflow/helpers/github_spec.rb @@ -6,7 +6,7 @@ let(:hub) { Zenflow::Github.new('test-hub') } before(:each){ - hub.should_receive(:get_config).with('api.base.url').and_return("api-base-url") + expect(hub).to receive(:get_config).with('api.base.url').and_return("api-base-url") } context 'and use_default_when_value_is_nil is not specified' do @@ -32,7 +32,7 @@ let(:hub) { Zenflow::Github.new('test-hub') } before(:each){ - hub.should_receive(:get_config).with('api.base.url').and_return(nil) + expect(hub).to receive(:get_config).with('api.base.url').and_return(nil) } context 'and use_default_when_value_is_nil is not specified' do @@ -67,29 +67,29 @@ context 'when a github api base url is already saved' do before do - hub.should_receive(:api_base_url).twice.and_return(api_base_url) + expect(hub).to receive(:api_base_url).twice.and_return(api_base_url) end context 'and the user decides to set a new one' do before do - Zenflow.should_receive(:Ask).and_return('n') + expect(Zenflow).to receive(:Ask).and_return('n') end it 'asks for an api base url' do - Zenflow.should_receive(:Ask).and_return(api_base_url) - hub.should_receive(:set_config).with('api.base.url', api_base_url) + expect(Zenflow).to receive(:Ask).and_return(api_base_url) + expect(hub).to receive(:set_config).with('api.base.url', api_base_url) hub.set_api_base_url end end context 'and the user decides not to set a new one' do before do - Zenflow.should_receive(:Ask).and_return('y') + expect(Zenflow).to receive(:Ask).and_return('y') end it 'does not ask for an api base url' do - Zenflow.should_not_receive(:Ask) - hub.should_not_receive(:set_config) + expect(Zenflow).to_not receive(:Ask) + expect(hub).to_not receive(:set_config) hub.set_api_base_url end end @@ -97,12 +97,12 @@ context 'when an api base url is not already saved' do before do - hub.should_receive(:api_base_url).and_return(nil) + expect(hub).to receive(:api_base_url).and_return(nil) end it 'asks for an api base url' do - Zenflow.should_receive(:Ask).and_return(api_base_url) - hub.should_receive(:set_config).with('api.base.url', api_base_url) + expect(Zenflow).to receive(:Ask).and_return(api_base_url) + expect(hub).to receive(:set_config).with('api.base.url', api_base_url) hub.set_api_base_url end end @@ -113,7 +113,7 @@ let(:user){'github-user'} before(:each){ - hub.should_receive(:get_config).with('github.user').and_return(user) + expect(hub).to receive(:get_config).with('github.user').and_return(user) } it "returns the user" do @@ -127,29 +127,29 @@ context 'when a github user is already saved' do before do - hub.should_receive(:user).twice.and_return(user) + expect(hub).to receive(:user).twice.and_return(user) end context 'and the user decides to set a new one' do before do - Zenflow.should_receive(:Ask).and_return('n') + expect(Zenflow).to receive(:Ask).and_return('n') end it 'asks for a user' do - Zenflow.should_receive(:Ask).and_return(user) - hub.should_receive(:set_config).with('github.user', user) + expect(Zenflow).to receive(:Ask).and_return(user) + expect(hub).to receive(:set_config).with('github.user', user) hub.set_user end end context 'and the user decides not to set a new one' do before do - Zenflow.should_receive(:Ask).and_return('y') + expect(Zenflow).to receive(:Ask).and_return('y') end it 'does not ask for a user' do - Zenflow.should_not_receive(:Ask) - hub.should_not_receive(:set_config) + expect(Zenflow).to_not receive(:Ask) + expect(hub).to_not receive(:set_config) hub.set_user end end @@ -157,12 +157,12 @@ context 'when a user is not already saved' do before do - hub.should_receive(:user).and_return(nil) + expect(hub).to receive(:user).and_return(nil) end it 'asks for a user' do - Zenflow.should_receive(:Ask).and_return(user) - hub.should_receive(:set_config).with('github.user', user) + expect(Zenflow).to receive(:Ask).and_return(user) + expect(hub).to receive(:set_config).with('github.user', user) hub.set_user end end @@ -173,39 +173,39 @@ context 'when a zenflow_token is already saved' do before do - hub.should_receive(:zenflow_token).and_return('super secret token') + expect(hub).to receive(:zenflow_token).and_return('super secret token') end context 'and the user decides to set a new one' do before do - Zenflow.should_receive(:Ask).with("You already have a token from GitHub. Do you want to set a new one?", :options => ["y", "N"], :default => "n").and_return('y') + expect(Zenflow).to receive(:Ask).with("You already have a token from GitHub. Do you want to set a new one?", :options => ["y", "N"], :default => "n").and_return('y') end context 'and authorization succeeds' do before do - Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.") - hub.should_receive(:user).twice.and_return('adamkittelson') - hub.should_receive(:api_base_url).and_return('https://api.base.url') - Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"token": "super secure token"}') + expect(Zenflow).to receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.") + expect(hub).to receive(:user).twice.and_return('adamkittelson') + expect(hub).to receive(:api_base_url).and_return('https://api.base.url') + expect(Zenflow::Shell).to receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"token": "super secure token"}') end it 'authorizes with Github' do - hub.should_receive(:set_config).with('token', "super secure token") - Zenflow.should_receive("Log").with("Authorized!") + expect(hub).to receive(:set_config).with('token', "super secure token") + expect(Zenflow).to receive("Log").with("Authorized!") hub.authorize end end context 'and authorization fails' do before do - Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.") - hub.should_receive(:user).twice.and_return('adamkittelson') - hub.should_receive(:api_base_url).and_return('https://api.base.url') - Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"message": "failed to authorize, bummer"}') + expect(Zenflow).to receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.") + expect(hub).to receive(:user).twice.and_return('adamkittelson') + expect(hub).to receive(:api_base_url).and_return('https://api.base.url') + expect(Zenflow::Shell).to receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"message": "failed to authorize, bummer"}') end it 'authorizes with Github' do - Zenflow.should_receive("Log").with("Something went wrong. Error from GitHub was: failed to authorize, bummer") + expect(Zenflow).to receive("Log").with("Something went wrong. Error from GitHub was: failed to authorize, bummer") hub.authorize end end @@ -213,7 +213,7 @@ context 'and the user decides not to set a new one' do before do - Zenflow.should_receive(:Ask).and_return('n') + expect(Zenflow).to receive(:Ask).and_return('n') end it 'does not authorize with Github' do @@ -224,34 +224,34 @@ context 'when a zenflow_token is not already saved' do before do - hub.should_receive(:zenflow_token).and_return(nil) + expect(hub).to receive(:zenflow_token).and_return(nil) end context 'and authorization succeeds' do before do - Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.") - hub.should_receive(:user).twice.and_return('adamkittelson') - hub.should_receive(:api_base_url).and_return('https://api.base.url') - Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"token": "super secure token"}') + expect(Zenflow).to receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.") + expect(hub).to receive(:user).twice.and_return('adamkittelson') + expect(hub).to receive(:api_base_url).and_return('https://api.base.url') + expect(Zenflow::Shell).to receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"token": "super secure token"}') end it 'authorizes with Github' do - hub.should_receive(:set_config).with('token', "super secure token") - Zenflow.should_receive("Log").with("Authorized!") + expect(hub).to receive(:set_config).with('token', "super secure token") + expect(Zenflow).to receive("Log").with("Authorized!") hub.authorize end end context 'and authorization fails' do before do - Zenflow.should_receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.") - hub.should_receive(:user).twice.and_return('adamkittelson') - hub.should_receive(:api_base_url).and_return('https://api.base.url') - Zenflow::Shell.should_receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"message": "failed to authorize, bummer"}') + expect(Zenflow).to receive("Log").with("Authorizing with GitHub (adamkittelson@my-hub)... Enter your GitHub password.") + expect(hub).to receive(:user).twice.and_return('adamkittelson') + expect(hub).to receive(:api_base_url).and_return('https://api.base.url') + expect(Zenflow::Shell).to receive(:run).with(%{curl -u "adamkittelson" https://api.base.url/authorizations -d '{"scopes":["repo"], "note":"Zenflow"}' --silent}, :silent => true).and_return('{"message": "failed to authorize, bummer"}') end it 'does not authorize with Github' do - Zenflow.should_receive("Log").with("Something went wrong. Error from GitHub was: failed to authorize, bummer") + expect(Zenflow).to receive("Log").with("Something went wrong. Error from GitHub was: failed to authorize, bummer") hub.authorize end end @@ -263,7 +263,7 @@ context 'when the value is present' do before(:each){ - hub.should_receive(:get_config).with('user.agent.base').and_return("user-agent-base") + expect(hub).to receive(:get_config).with('user.agent.base').and_return("user-agent-base") } context 'and use_default_when_value_is_nil is not specified' do @@ -287,7 +287,7 @@ context 'when the value is absent' do before(:each){ - hub.should_receive(:get_config).with('user.agent.base').and_return(nil) + expect(hub).to receive(:get_config).with('user.agent.base').and_return(nil) } context 'and use_default_when_value_is_nil is not specified' do @@ -316,29 +316,29 @@ context 'when a github user agent base is already saved' do before do - hub.should_receive(:user_agent_base).twice.and_return(user_agent_base) + expect(hub).to receive(:user_agent_base).twice.and_return(user_agent_base) end context 'and the user decides to set a new one' do before do - Zenflow.should_receive(:Ask).and_return('n') + expect(Zenflow).to receive(:Ask).and_return('n') end it 'asks for a user agent base' do - Zenflow.should_receive(:Ask).and_return(user_agent_base) - hub.should_receive(:set_config).with('user.agent.base', user_agent_base) + expect(Zenflow).to receive(:Ask).and_return(user_agent_base) + expect(hub).to receive(:set_config).with('user.agent.base', user_agent_base) hub.set_user_agent_base end end context 'and the user decides not to set a new one' do before do - Zenflow.should_receive(:Ask).and_return('y') + expect(Zenflow).to receive(:Ask).and_return('y') end it 'does not ask for a user agent base' do - Zenflow.should_not_receive(:Ask) - hub.should_not_receive(:set_config) + expect(Zenflow).to_not receive(:Ask) + expect(hub).to_not receive(:set_config) hub.set_user_agent_base end end @@ -346,12 +346,12 @@ context 'when a user agent base is not already saved' do before do - hub.should_receive(:user_agent_base).and_return(nil) + expect(hub).to receive(:user_agent_base).and_return(nil) end it 'asks for a user agent base' do - Zenflow.should_receive(:Ask).and_return(user_agent_base) - hub.should_receive(:set_config).with('user.agent.base', user_agent_base) + expect(Zenflow).to receive(:Ask).and_return(user_agent_base) + expect(hub).to receive(:set_config).with('user.agent.base', user_agent_base) hub.set_user_agent_base end end @@ -360,7 +360,7 @@ describe '.current' do context 'when the current repo is nil' do before(:each){ - Zenflow::Repo.should_receive(:hub).and_return(nil) + expect(Zenflow::Repo).to receive(:hub).and_return(nil) } it 'returns the default hub' do @@ -370,7 +370,7 @@ context 'when the current repo is not nil' do before(:each){ - Zenflow::Repo.should_receive(:hub).and_return('current.repo.hub') + expect(Zenflow::Repo).to receive(:hub).and_return('current.repo.hub') } it 'returns the current repo\'s hub' do @@ -442,7 +442,7 @@ let(:hub){Zenflow::Github.new('test-hub')} it 'gets the correct global config parameter' do - hub.should_receive(:get_global_config).with("zenflow.hub.test-hub.test-key") + expect(hub).to receive(:get_global_config).with("zenflow.hub.test-hub.test-key") hub.get_config('test-key') end end @@ -451,7 +451,7 @@ let(:hub){Zenflow::Github.new('test-hub')} it 'sets the correct global config parameter' do - hub.should_receive(:set_global_config).with("zenflow.hub.test-hub.test-key", "test-value") + expect(hub).to receive(:set_global_config).with("zenflow.hub.test-hub.test-key", "test-value") hub.set_config('test-key', 'test-value') end end @@ -461,7 +461,7 @@ context 'when value is present' do before(:each){ - Zenflow::Shell.should_receive(:run).with('git config --get key', silent: true).and_return('value') + expect(Zenflow::Shell).to receive(:run).with('git config --get key', silent: true).and_return('value') } it 'returns the value' do @@ -471,7 +471,7 @@ context 'when value is missing' do before(:each){ - Zenflow::Shell.should_receive(:run).with('git config --get key', silent: true).and_return('') + expect(Zenflow::Shell).to receive(:run).with('git config --get key', silent: true).and_return('') } it 'returns nil' do @@ -484,7 +484,7 @@ let(:hub){Zenflow::Github.new('test-hub')} before(:each){ - Zenflow::Shell.should_receive(:run).with('git config --global key value', silent: true) + expect(Zenflow::Shell).to receive(:run).with('git config --global key value', silent: true) } it 'sets the value' do @@ -507,7 +507,7 @@ let(:hub){Zenflow::Github.new('my-hub')} it 'returns the expected array' do - hub.should_receive(:get_config).with('key').and_return('config-value') + expect(hub).to receive(:get_config).with('key').and_return('config-value') expect(hub.describe_parameter('name', 'key', 'value')).to eq( ['name', 'zenflow.hub.my-hub.key', 'config-value', 'value'] @@ -520,10 +520,10 @@ let(:hub){Zenflow::Github.new('my-hub')} it 'returns the expected data' do - hub.should_receive(:get_config).twice.with('api.base.url').and_return('api-base-url-config-value') - hub.should_receive(:get_config).twice.with('github.user').and_return('github-user-config-value') - hub.should_receive(:get_config).twice.with('token').and_return('token-config-value') - hub.should_receive(:get_config).twice.with('user.agent.base').and_return('user-agent-base-config-value') + expect(hub).to receive(:get_config).twice.with('api.base.url').and_return('api-base-url-config-value') + expect(hub).to receive(:get_config).twice.with('github.user').and_return('github-user-config-value') + expect(hub).to receive(:get_config).twice.with('token').and_return('token-config-value') + expect(hub).to receive(:get_config).twice.with('user.agent.base').and_return('user-agent-base-config-value') expect(hub.describe).to eq([ ['API Base URL', 'zenflow.hub.my-hub.api.base.url', 'api-base-url-config-value', 'api-base-url-config-value'], @@ -538,10 +538,10 @@ let(:hub){Zenflow::Github.new('my-hub')} it 'returns the expected data' do - hub.should_receive(:get_config).twice.with('api.base.url').and_return(nil) - hub.should_receive(:get_config).twice.with('github.user').and_return(nil) - hub.should_receive(:get_config).twice.with('token').and_return(nil) - hub.should_receive(:get_config).twice.with('user.agent.base').and_return(nil) + expect(hub).to receive(:get_config).twice.with('api.base.url').and_return(nil) + expect(hub).to receive(:get_config).twice.with('github.user').and_return(nil) + expect(hub).to receive(:get_config).twice.with('token').and_return(nil) + expect(hub).to receive(:get_config).twice.with('user.agent.base').and_return(nil) expect(hub.describe).to eq([ ['API Base URL', 'zenflow.hub.my-hub.api.base.url', nil, 'https://api.github.com'], @@ -556,10 +556,10 @@ let(:hub){Zenflow::Github.new(Zenflow::Github::DEFAULT_HUB)} it 'returns the expected data' do - hub.should_receive(:get_config).twice.with('api.base.url').and_return(nil) - hub.should_receive(:get_config).twice.with('github.user').and_return(nil) - hub.should_receive(:get_config).twice.with('token').and_return(nil) - hub.should_receive(:get_config).twice.with('user.agent.base').and_return(nil) + expect(hub).to receive(:get_config).twice.with('api.base.url').and_return(nil) + expect(hub).to receive(:get_config).twice.with('github.user').and_return(nil) + expect(hub).to receive(:get_config).twice.with('token').and_return(nil) + expect(hub).to receive(:get_config).twice.with('user.agent.base').and_return(nil) expect(hub.describe).to eq([ ['API Base URL', 'zenflow.api.base.url', nil, 'https://api.github.com'], diff --git a/spec/zenflow/helpers/help_spec.rb b/spec/zenflow/helpers/help_spec.rb index 7fd7b17..302efe8 100644 --- a/spec/zenflow/helpers/help_spec.rb +++ b/spec/zenflow/helpers/help_spec.rb @@ -21,15 +21,15 @@ context "#unknown_command" do describe "when the command is missing" do it "logs the error and exits" do - Zenflow.should_receive(:Log).with "Missing command", :color => :red - lambda {Zenflow::Help.new.unknown_command}.should raise_error(SystemExit) + expect(Zenflow).to receive(:Log).with "Missing command", :color => :red + expect(lambda {Zenflow::Help.new.unknown_command}).to raise_error(SystemExit) end end describe "when the command is present" do it "logs the error and exits" do - Zenflow.should_receive(:Log).with "Unknown command \"test-unknown_command\"", :color => :red - lambda {Zenflow::Help.new(:command => 'test-unknown_command').unknown_command}.should raise_error(SystemExit) + expect(Zenflow).to receive(:Log).with "Unknown command \"test-unknown_command\"", :color => :red + expect(lambda {Zenflow::Help.new(:command => 'test-unknown_command').unknown_command}).to raise_error(SystemExit) end end end diff --git a/spec/zenflow/helpers/log_spec.rb b/spec/zenflow/helpers/log_spec.rb index 9423ad9..d64b668 100644 --- a/spec/zenflow/helpers/log_spec.rb +++ b/spec/zenflow/helpers/log_spec.rb @@ -4,26 +4,26 @@ describe 'Log' do context 'with indentation' do before(:each) do - Zenflow.stub(:LogToFile) + allow(Zenflow).to receive(:LogToFile) end it 'indents the text' do - $stdout.should_receive(:puts).with(/\s+foo/) + expect($stdout).to receive(:puts).with(/\s+foo/) Zenflow.Log('foo', indent: true) end it 'adds an arrow the text' do - $stdout.should_receive(:puts).with(/-----> foo/) + expect($stdout).to receive(:puts).with(/-----> foo/) Zenflow.Log('foo', arrows: true) end it 'colorizes the text' do - $stdout.should_receive(:puts).with(/foo/) + expect($stdout).to receive(:puts).with(/foo/) Zenflow.Log('foo', color: :blue, arrows: false) end it 'does not colorize the text' do - $stdout.should_receive(:puts).with('foo') + expect($stdout).to receive(:puts).with('foo') Zenflow.Log('foo', color: false, arrows: false) end end diff --git a/spec/zenflow/helpers/pull_request_spec.rb b/spec/zenflow/helpers/pull_request_spec.rb index 6347110..f502ed7 100644 --- a/spec/zenflow/helpers/pull_request_spec.rb +++ b/spec/zenflow/helpers/pull_request_spec.rb @@ -2,8 +2,8 @@ describe Zenflow::PullRequest do before(:each){ - Zenflow::Github.stub(:zenflow_token).and_return('zenflow-token') - Zenflow::Github.stub(:user).and_return('github-user') + allow(Zenflow::Github).to receive(:zenflow_token).and_return('zenflow-token') + allow(Zenflow::Github).to receive(:user).and_return('github-user') Zenflow::GithubRequest.base_uri 'https://api.github.com/repos/zencoder/zenflow-example' } @@ -19,7 +19,7 @@ end describe '.find_by_ref' do - before(:each){Zenflow.should_receive(:Log).with(Regexp.new('Looking up'))} + before(:each){expect(Zenflow).to receive(:Log).with(Regexp.new('Looking up'))} context 'existing ref', vcr: { cassette_name: "pull request by ref" } do let(:pull_request){Zenflow::PullRequest.find_by_ref('feature/example')} @@ -33,7 +33,7 @@ end describe '.find_by_ref!' do - before(:each){Zenflow.should_receive(:Log).with(Regexp.new('Looking up'))} + before(:each){expect(Zenflow).to receive(:Log).with(Regexp.new('Looking up'))} context 'existing ref', vcr: { cassette_name: "pull request by ref" } do let(:pull_request){Zenflow::PullRequest.find_by_ref!('feature/example')} @@ -44,21 +44,21 @@ let(:ref){'feature/foo'} it 'logs the failure' do - Zenflow.should_receive(:Log).with(Regexp.new(ref), color: :red) + expect(Zenflow).to receive(:Log).with(Regexp.new(ref), color: :red) expect{Zenflow::PullRequest.find_by_ref!(ref)}.to raise_error(SystemExit) end end end describe '.exist?' do - before(:each){Zenflow.should_receive(:Log).with(Regexp.new('Looking up'))} + before(:each){expect(Zenflow).to receive(:Log).with(Regexp.new('Looking up'))} context 'a valid pull', vcr: { cassette_name: "existing pull request" } do - it{expect(Zenflow::PullRequest.exist?('feature/example')).to be_true} + it{expect(Zenflow::PullRequest.exist?('feature/example')).to be true} end context 'an invalid pull', vcr: { cassette_name: "unexisting pull request" } do - it{expect(Zenflow::PullRequest.exist?('feature/foo')).to be_false} + it{expect(Zenflow::PullRequest.exist?('feature/foo')).to be false} end end @@ -90,12 +90,12 @@ describe '#valid?' do context 'good request', vcr: { cassette_name: "create pull request" } do let(:request){Zenflow::PullRequest.create(good_request_options)} - it{expect(request.valid?).to be_true} + it{expect(request.valid?).to be_truthy} end context 'bad request', vcr: { cassette_name: "create bad pull request" } do let(:request){Zenflow::PullRequest.create(bad_request_options)} - it{expect(request.valid?).to be_false} + it{expect(request.valid?).to be_falsey} end end diff --git a/spec/zenflow/helpers/repo_spec.rb b/spec/zenflow/helpers/repo_spec.rb index 1ac011b..1e21679 100644 --- a/spec/zenflow/helpers/repo_spec.rb +++ b/spec/zenflow/helpers/repo_spec.rb @@ -3,7 +3,7 @@ describe Zenflow::Repo do describe '.hub' do before(:each){ - Zenflow::Repo.should_receive(:url).twice.and_return("git@github.com:zencoder/zenflow.git") + expect(Zenflow::Repo).to receive(:url).twice.and_return("git@github.com:zencoder/zenflow.git") } it 'selects the hub from the git remote -v url' do @@ -13,7 +13,7 @@ describe '.slug' do before(:each){ - Zenflow::Repo.should_receive(:url).twice.and_return("git@github.com:zencoder/zenflow.git") + expect(Zenflow::Repo).to receive(:url).twice.and_return("git@github.com:zencoder/zenflow.git") } it 'selects the repo slug from the git remote -v url' do diff --git a/spec/zenflow/helpers/shell_spec.rb b/spec/zenflow/helpers/shell_spec.rb index 0de0925..05a6381 100644 --- a/spec/zenflow/helpers/shell_spec.rb +++ b/spec/zenflow/helpers/shell_spec.rb @@ -4,19 +4,19 @@ describe '.failed!' do before(:all){ Zenflow::Shell.failed!(404) } - it{expect(Zenflow::Shell.instance_variable_get('@failed')).to be_true} + it{expect(Zenflow::Shell.instance_variable_get('@failed')).to be true} it{expect(Zenflow::Shell.instance_variable_get('@status')).to eq(404)} end describe '.failed?' do context 'when failed' do before(:all){ Zenflow::Shell.failed!('bad') } - it{expect(Zenflow::Shell.failed?).to be_true} + it{expect(Zenflow::Shell.failed?).to be true} end context 'when not failed' do before(:all){ Zenflow::Shell.instance_variable_set('@failed', false) } - it{expect(Zenflow::Shell.failed?).to be_false} + it{expect(Zenflow::Shell.failed?).to be false} end end @@ -35,7 +35,7 @@ describe '.[]' do let(:command){'foo'} it 'runs the command' do - Zenflow::Shell.should_receive(:run).with(command) + expect(Zenflow::Shell).to receive(:run).with(command) Zenflow::Shell[command] end end @@ -47,13 +47,13 @@ let(:command){'ls'} it 'runs the command' do - Zenflow::Shell.should_receive(:run_without_output).with(command, {silent: true}) + expect(Zenflow::Shell).to receive(:run_without_output).with(command, {silent: true}) Zenflow::Shell.run(command, silent: true) end it 'logs the command' do allow(Zenflow::Shell).to receive(:run_without_output).and_return(true) - Zenflow.should_receive(:LogToFile).once.with("$ #{command}\n") + expect(Zenflow).to receive(:LogToFile).once.with("$ #{command}\n") Zenflow::Shell.run(command, silent: true) end end @@ -63,13 +63,13 @@ it 'runs the command' do allow(Zenflow).to receive(:Log) - Zenflow::Shell.should_receive(:run_with_output).with(command, {}) + expect(Zenflow::Shell).to receive(:run_with_output).with(command, {}) Zenflow::Shell.run(command) end it 'logs the command' do allow(Zenflow::Shell).to receive(:run_with_output).and_return(true) - Zenflow.should_receive(:Log).once.with( + expect(Zenflow).to receive(:Log).once.with( "$ #{command}", arrows: false, color: :yellow ) Zenflow::Shell.run(command) @@ -82,8 +82,8 @@ let(:response){"foo\nbar"} before(:each){ - Zenflow::Shell.should_receive(:run_with_result_check).with(command,{}).and_return(response) - Zenflow::Shell.should_receive(:puts).with(Regexp.new(response)) + expect(Zenflow::Shell).to receive(:run_with_result_check).with(command,{}).and_return(response) + expect(Zenflow::Shell).to receive(:puts).with(Regexp.new(response)) } subject{ Zenflow::Shell.run_with_output(command) } @@ -95,7 +95,7 @@ let(:response){"foo\nbar"} before(:each){ - Zenflow::Shell.should_receive(:run_with_result_check).with(command,{}).and_return(response) + expect(Zenflow::Shell).to receive(:run_with_result_check).with(command,{}).and_return(response) } subject{ Zenflow::Shell.run_with_output(command) } @@ -107,7 +107,7 @@ let(:response){"foo\nbar"} before(:each){ - Zenflow::Shell.should_receive(:`).with(command).and_return(response) + expect(Zenflow::Shell).to receive(:`).with(command).and_return(response) } subject{Zenflow::Shell.run_with_result_check(command)} @@ -120,11 +120,11 @@ before(:each){ allow(Zenflow::Shell).to receive(:last_exit_status).and_return(response) - Zenflow::Shell.should_receive(:`).with(command).and_return(response) - Zenflow::Shell.should_receive(:puts).with(Regexp.new(response)) - Zenflow.should_receive(:Log).with(/aborted/, color: :red) - Zenflow.should_receive(:Log).with(/exit status: #{response}/i, color: :red, indent: true) - Zenflow.should_receive(:Log).with(/following commands manually/, color: :red) + expect(Zenflow::Shell).to receive(:`).with(command).and_return(response) + expect(Zenflow::Shell).to receive(:puts).with(Regexp.new(response)) + expect(Zenflow).to receive(:Log).with(/aborted/, color: :red) + expect(Zenflow).to receive(:Log).with(/exit status: #{response}/i, color: :red, indent: true) + expect(Zenflow).to receive(:Log).with(/following commands manually/, color: :red) } subject{Zenflow::Shell.run_with_result_check(command)} diff --git a/spec/zenflow/helpers/version_spec.rb b/spec/zenflow/helpers/version_spec.rb index a850ee8..a24d275 100644 --- a/spec/zenflow/helpers/version_spec.rb +++ b/spec/zenflow/helpers/version_spec.rb @@ -15,7 +15,7 @@ describe '.current' do before(:each) do - YAML.stub(:load_file).and_return( + allow(YAML).to receive(:load_file).and_return( {'major' => 1, 'minor' => 2, 'patch' => 4, 'pre' => nil} ) end @@ -29,7 +29,7 @@ describe '.bump' do before(:each) do - Zenflow::Version.stub(:current).and_return(Zenflow::Version[1,2,4]) + allow(Zenflow::Version).to receive(:current).and_return(Zenflow::Version[1,2,4]) end context 'patch' do From 2f8803e093f0c29c6138346c0dc043c8ee88a6b3 Mon Sep 17 00:00:00 2001 From: Brian Martinez <1622554+stoicAlchemist@users.noreply.github.com> Date: Mon, 16 Aug 2021 20:56:25 -0500 Subject: [PATCH 3/3] fix(test): Replacement of expectancies mistake, now it works --- spec/zenflow/helpers/ask_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/zenflow/helpers/ask_spec.rb b/spec/zenflow/helpers/ask_spec.rb index 07063d9..d479cc6 100644 --- a/spec/zenflow/helpers/ask_spec.rb +++ b/spec/zenflow/helpers/ask_spec.rb @@ -9,22 +9,22 @@ end it "displays a prompt" do - allow(Zenflow::Query).to receive(:print).with(">> How are you? ") + expect(Zenflow::Query).to receive(:print).with(">> How are you? ") Zenflow::Ask("How are you?") end it "displays a prompt with options" do - allow(Zenflow::Query).to receive(:print).with(">> How are you? [good/bad] ") + expect(Zenflow::Query).to receive(:print).with(">> How are you? [good/bad] ") Zenflow::Ask("How are you?", options: ["good", "bad"]) end it "displays a prompt with default" do - allow(Zenflow::Query).to receive(:print).with(">> How are you? [good] ") + expect(Zenflow::Query).to receive(:print).with(">> How are you? [good] ") Zenflow::Ask("How are you?", default: "good") end it "displays a prompt with options and default" do - allow(Zenflow::Query).to receive(:print).with(">> How are you? [good/bad] ") + expect(Zenflow::Query).to receive(:print).with(">> How are you? [good/bad] ") Zenflow::Ask("How are you?", options: ["good", "bad"], default: "good") end @@ -41,10 +41,10 @@ context "on interrupt" do before(:each) do - allow(Zenflow::Query).to receive(:ask_question).once.and_return('foo') + expect(Zenflow::Query).to receive(:ask_question).once.and_return('foo') expect(Zenflow::Query).to receive(:handle_response).once.and_raise(Interrupt) expect(Zenflow).to receive(:LogToFile) - allow($stdout).to receive(:puts).at_least(:once) + expect($stdout).to receive(:puts).at_least(:once) end it{expect{Zenflow::Ask('howdy')}.to raise_error(SystemExit)} @@ -71,7 +71,7 @@ describe '.prompt_for_answer' do before(:each) do expect(Zenflow::Query).to receive(:print).with(">> Hi? [yes/bye] ") - allow(STDIN).to receive(:gets).and_return("bye") + expect(STDIN).to receive(:gets).and_return("bye") end it{expect(