Skip to content

Commit

Permalink
Fix spec for TestUnitRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturT committed Oct 2, 2017
1 parent 0803311 commit 305918a
Showing 1 changed file with 31 additions and 57 deletions.
88 changes: 31 additions & 57 deletions spec/knapsack_pro/runners/test_unit_runner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,81 +1,55 @@
require 'rspec/core/rake_task'
require 'test/unit'

describe KnapsackPro::Runners::TestUnitRunner do
subject { described_class.new(KnapsackPro::Adapters::TestUnitAdapter) }

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
Expand Down

0 comments on commit 305918a

Please sign in to comment.