From 305918a0d881348ebcf9fbfcbd345c59648b831c Mon Sep 17 00:00:00 2001 From: ArturT Date: Sun, 1 Oct 2017 21:15:18 +0200 Subject: [PATCH] Fix spec for TestUnitRunner --- .../runners/test_unit_runner_spec.rb | 88 +++++++------------ 1 file changed, 31 insertions(+), 57 deletions(-) diff --git a/spec/knapsack_pro/runners/test_unit_runner_spec.rb b/spec/knapsack_pro/runners/test_unit_runner_spec.rb index 49bbab83..653b3a25 100644 --- a/spec/knapsack_pro/runners/test_unit_runner_spec.rb +++ b/spec/knapsack_pro/runners/test_unit_runner_spec.rb @@ -1,4 +1,4 @@ -require 'rspec/core/rake_task' +require 'test/unit' describe KnapsackPro::Runners::TestUnitRunner do subject { described_class.new(KnapsackPro::Adapters::TestUnitAdapter) } @@ -6,76 +6,50 @@ it { should be_kind_of KnapsackPro::Runners::BaseRunner } describe '.run' do - let(:args) { '--profile --color' } - - let(:test_suite_token_test_unit) { 'fake-token' } + let(:args) { '--verbose --order=random' } subject { described_class.run(args) } before do - expect(KnapsackPro::Config::Env).to receive(:test_suite_token_test_unit).and_return(test_suite_token_test_unit) - - expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT', test_suite_token_test_unit) - expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_RECORDING_ENABLED', 'true') - - expect(described_class).to receive(:new) - .with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner) + stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT' => 'test-unit-token' }) end context 'when test files were returned by Knapsack Pro API' do - let(:test_dir) { 'fake-test-dir' } - let(:test_file_paths) { double(:test_file_paths) } - let(:runner) do - instance_double(described_class, - test_dir: test_dir, - test_file_paths: test_file_paths, - test_files_to_execute_exist?: true) - end - let(:task) { double } - - before do - #expect(Rake::Task).to receive(:[]).with('knapsack_pro:rspec_run').at_least(1).and_return(task) - - #t = double - #expect(RSpec::Core::RakeTask).to receive(:new).with('knapsack_pro:rspec_run').and_yield(t) - #expect(t).to receive(:rspec_opts=).with('--profile --color --default-path fake-test-dir') - #expect(t).to receive(:pattern=).with(test_file_paths) - end + it 'runs tests' do + test_file_paths = ['test-unit_fake/a_test.rb', 'test-unit_fake/b_test.rb'] + runner = instance_double(described_class, + test_dir: 'test-unit_fake', + test_file_paths: test_file_paths, + test_files_to_execute_exist?: true) + expect(described_class).to receive(:new) + .with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner) + + auto_runner_exit_code = 0 + expect(Test::Unit::AutoRunner).to receive(:run) do |flag, test_dir, cli_args| + expect(flag).to be true + expect(test_dir).to eq 'test-unit_fake' + expect(cli_args.size).to eq 4 + expect(cli_args[0]).to eq '--verbose' + expect(cli_args[1]).to eq '--order=random' + expect(cli_args[2]).to end_with 'test-unit_fake/a_test.rb' + expect(cli_args[3]).to end_with 'test-unit_fake/b_test.rb' + end.and_return(auto_runner_exit_code) + expect(described_class).to receive(:exit).with(auto_runner_exit_code) - context 'when task already exists' do - before do - #expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:rspec_run').and_return(true) - #expect(task).to receive(:clear) - end - - it do - #result = double(:result) - #expect(task).to receive(:invoke).and_return(result) - #expect(subject).to eq result - end - end - - context "when task doesn't exist" do - before do - #expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:rspec_run').and_return(false) - #expect(task).not_to receive(:clear) - end + subject - it do - #result = double(:result) - #expect(task).to receive(:invoke).and_return(result) - #expect(subject).to eq result - end + expect(ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']).to eq 'test-unit-token' + expect(ENV['KNAPSACK_PRO_RECORDING_ENABLED']).to eq 'true' end end context 'when test files were not returned by Knapsack Pro API' do - let(:runner) do - instance_double(described_class, - test_files_to_execute_exist?: false) - end - it "doesn't run tests" do + runner = instance_double(described_class, + test_files_to_execute_exist?: false) + expect(described_class).to receive(:new) + .with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner) + subject end end