Skip to content

Commit

Permalink
(FIXUP) Add acceptance tests for pdk test unit
Browse files Browse the repository at this point in the history
  • Loading branch information
scotje committed Jun 22, 2017
1 parent 225ba1d commit 282a78b
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions spec/acceptance/test_unit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require 'spec_helper_acceptance'
require 'fileutils'

describe 'Running unit tests' do
context 'with a fresh module' do
include_context 'in a new module', 'unit_test_module_new'

describe command('pdk test unit') do
its(:exit_status) { is_expected.to eq(0) }
its(:stdout) { is_expected.to match(%r{no examples found}i) }
its(:stderr) { is_expected.to match(%r{running unit tests}i) }
end
end

context 'with passing tests' do
include_context 'in a new module', 'unit_test_module_pass'

before(:all) do
FileUtils.mkdir_p('spec/unit')
File.open('spec/unit/passing_spec.rb', 'w') do |f|
f.puts <<-EOF
require 'spec_helper'
RSpec.describe 'test' do
it 'should pass' do
expect(true).to eq(true)
end
end
EOF
end
end

describe command('pdk test unit') do
its(:exit_status) { is_expected.to eq(0) }
its(:stderr) { is_expected.to match(%r{running unit tests.*1 tests.*0 errors.*0 failures}im) }
end
end

context 'with failing tests' do
include_context 'in a new module', 'unit_test_module_fail'

before(:all) do
FileUtils.mkdir_p('spec/unit')
File.open('spec/unit/failing_spec.rb', 'w') do |f|
f.puts <<-EOF
require 'spec_helper'
RSpec.describe 'failing test' do
it 'should pass' do
expect(false).to eq(true)
end
end
EOF
end
end

describe command('pdk test unit') do
its(:exit_status) { is_expected.not_to eq(0) }
its(:stdout) { is_expected.to match(%r{failed.*expected: true got: false}i) }
its(:stderr) { is_expected.to match(%r{running unit tests.*1 tests.*0 errors.*1 failures}im) }
end
end

context 'with pending tests' do
include_context 'in a new module', 'unit_test_module_pending'

before(:all) do
FileUtils.mkdir_p('spec/unit')
File.open('spec/unit/pending_spec.rb', 'w') do |f|
f.puts <<-EOF
require 'spec_helper'
RSpec.describe 'pending test' do
it 'should pass' do
pending
expect(false).to eq(true)
end
end
EOF
end
end

describe command('pdk test unit') do
its(:exit_status) { is_expected.to eq(0) }
its(:stderr) { is_expected.to match(%r{running unit tests.*1 tests.*0 errors.*0 failures.*1 pending}im) }
end
end
end

0 comments on commit 282a78b

Please sign in to comment.