Skip to content

Commit

Permalink
Unit test for testing --run-todo flag (#1492)
Browse files Browse the repository at this point in the history
Unit test for testing --run-todo flag
  • Loading branch information
rambleraptor committed Nov 5, 2019
2 parents cecaa8a + 411fe66 commit 88b0a17
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/sass_spec/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.parse
verbose: false,
filter: "",
limit: -1,
implementation: 'sass'
}

OptionParser.new do |opts|
Expand Down
18 changes: 17 additions & 1 deletion tests/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@
it 'runs a single spec' do
run_command "#{Dir.pwd}/sass-spec.rb --command "\
"'#{Dir.pwd}/tests/sass_stub' "\
"#{Dir.pwd}/tests/fixtures/colors"
"#{Dir.pwd}/tests/fixtures/basic"
expect(last_command_started).to be_successfully_executed
end

it 'should not run todo specs by default' do
run_command "#{Dir.pwd}/sass-spec.rb --command "\
"'#{Dir.pwd}/tests/sass_stub' "\
"#{Dir.pwd}/tests/fixtures/todo"
expect(last_command_started).to be_successfully_executed
expect(test_results(last_command_started.output)[:skips]).to eq 1
end

it 'should run todo specs with --run-todo flag' do
run_command "#{Dir.pwd}/sass-spec.rb --run-todo --command "\
"'#{Dir.pwd}/tests/sass_stub' "\
"#{Dir.pwd}/tests/fixtures/todo"
expect(last_command_started).to be_successfully_executed
expect(test_results(last_command_started.output)[:skips]).to eq 0
end
end
File renamed without changes.
29 changes: 29 additions & 0 deletions tests/fixtures/todo/basic.hrx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<===> no_todo/input.scss
p {
color: #ff8000;
}

<===> no_todo/output.css
input: ["--precision", "10", "-t", "expanded", "input.scss"]
file: p {
color: #ff8000;
}

<===>
=============================================================
<===> todo/options.yml
---
:todo:
- sass/sass#0000

<===> todo/input.scss
p {
color: #ff8000;
}

<===> todo/output.css
input: ["--precision", "10", "-t", "expanded", "input.scss"]
file: p {
color: #ff8000;
}

12 changes: 12 additions & 0 deletions tests/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@

require 'rspec'
require 'aruba/rspec'

# Given the output of sass-spec,
# return the number of tests in
# each state (success, failed, etc)
def test_results(output)
results = {}
matches = output.match(
/(?<runs>\d+) runs, (?<assertions>\d+) assertions, (?<failures>\d+) failures, (?<errors>\d+) errors, (?<skips>\d+) skips/
)
matches.names.each { |k, v| results[k.to_sym] = matches[k].to_i }
results
end
16 changes: 8 additions & 8 deletions tests/test_case_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@
require 'sass_spec'

def create_options_yaml(folder, dictionary)
FileUtils.mkdir_p("tests/fixtures/#{folder}")
File.write("tests/fixtures/#{folder}/options.yml", dictionary.to_yaml)
FileUtils.mkdir_p("tests/metadata/#{folder}")
File.write("tests/metadata/#{folder}/options.yml", dictionary.to_yaml)
end

def cleanup(folder)
FileUtils.remove_dir("tests/fixtures/#{folder}")
FileUtils.remove_dir("tests/metadata/#{folder}")
end

describe SassSpec::TestCaseMetadata do
context 'should ignore impl when given ignore_for' do
before { create_options_yaml('ignore', ignore_for: ['dart_sass']) }
after { cleanup('ignore') }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/fixtures/ignore')).ignore_for?('dart_sass') }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/metadata/ignore')).ignore_for?('dart_sass') }
it { is_expected.to be true }
end

context 'should ignore impl when given only_on' do
before { create_options_yaml('only_on', only_on: ['dart_sass']) }
after { cleanup('only_on') }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/fixtures/only_on')).ignore_for?('libsass') }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/metadata/only_on')).ignore_for?('libsass') }
it { is_expected.to be true }
end

context 'should have precision' do
before { create_options_yaml('precision', precision: 10) }
after { cleanup('precision') }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/fixtures/precision')).precision }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/metadata/precision')).precision }
it { is_expected.to eq 10 }
end

context 'should have todos for an impl' do
before { create_options_yaml('todo', todo: ['sass/libsass#2342']) }
after { cleanup('todo') }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/fixtures/todo')).todo?('libsass') }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/metadata/todo')).todo?('libsass') }
it { is_expected.to be true }
end

context 'should have warning todos for an impl' do
before { create_options_yaml('warning', warning_todo: ['sass/libsass#2342']) }
after { cleanup('warning') }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/fixtures/warning')).warning_todo?('libsass') }
subject { SassSpec::TestCaseMetadata.new(SassSpec::Directory.new('tests/metadata/warning')).warning_todo?('libsass') }
it { is_expected.to be true }
end
end

0 comments on commit 88b0a17

Please sign in to comment.