Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test for testing --run-todo flag #1492

Merged
merged 8 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These run_command invocations have a lot of boilerplate... consider factoring out a helper function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely agree! I've already got a PR going for the next test, so I'll make a helper function there.

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