Skip to content

Commit

Permalink
Wrap rspec doubles
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Feb 17, 2024
1 parent 01cc95d commit aade8c8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 20 deletions.
10 changes: 7 additions & 3 deletions spec/sass/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@
]
end

let(:logger_instance_double) do
instance_double(Proc, call: nil)
end

let(:logger) do
{
debug: instance_double(Proc, call: nil)
debug: ->(*args, **kwargs) { logger_instance_double.call(*args, **kwargs) }
}
end

describe 'compile_string' do
it 'performs complete compilations' do
result = compiler.compile_string('@import "bar"; .fn {value: foo(baz)}', importers:, functions:, logger:)
expect(result.css).to eq(".import {\n value: bar;\n}\n\n.fn {\n value: baz;\n}")
expect(logger[:debug]).to have_received(:call).once
expect(logger_instance_double).to have_received(:call).once
end

it 'performs compilations in callbacks' do
Expand Down Expand Up @@ -92,7 +96,7 @@
dir.write({ 'input.scss' => '@import "bar"; .fn {value: foo(bar)}' })
result = compiler.compile(dir.path('input.scss'), importers:, functions:, logger:)
expect(result.css).to eq(".import {\n value: bar;\n}\n\n.fn {\n value: bar;\n}")
expect(logger[:debug]).to have_received(:call).once
expect(logger_instance_double).to have_received(:call).once
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/sass/value/argument_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Sass.compile_string(
'a {b: foo(x, y, z)}',
functions: {
'foo($arg...)': fn
'foo($arg...)': ->(args) { fn.call(args) }
}
).css
).to eq('')
Expand All @@ -46,7 +46,7 @@
Sass.compile_string(
'a {b: foo($bar: baz)}',
functions: {
'foo($arg...)': fn
'foo($arg...)': ->(args) { fn.call(args) }
}
).css
).to eq('')
Expand All @@ -66,7 +66,7 @@
Sass.compile_string(
'a {b: foo($bar: baz)}',
functions: {
'foo($arg...)': fn
'foo($arg...)': ->(args) { fn.call(args) }
}
).css
end.to raise_sass_compile_error.with_line(0).without_url
Expand Down
6 changes: 3 additions & 3 deletions spec/sass/value/function_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
a {b: meta.call(foo(meta.get-function('plusOne')), 2)}
",
functions: {
'foo($arg)': fn
'foo($arg)': ->(args) { fn.call(args) }
}
).css
).to eq("a {\n b: 3;\n}")
Expand All @@ -60,7 +60,7 @@
a {b: meta.call(foo(), 2)}
",
functions: {
'foo()': fn
'foo()': ->(args) { fn.call(args) }
}
).css
).to eq("a {\n b: 3;\n}")
Expand Down Expand Up @@ -91,7 +91,7 @@
Sass.compile_string(
'a {b: inspect(foo())}',
functions: {
'foo()': fn
'foo()': ->(args) { fn.call(args) }
}
)
end.to raise_sass_compile_error.with_line(0).without_url
Expand Down
2 changes: 1 addition & 1 deletion spec/sass/value/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@include meta.apply(foo(meta.get-mixin('a')));
",
functions: {
'foo($arg)': fn
'foo($arg)': ->(args) { fn.call(args) }
}
).css
).to eq("a {\n b: c;\n}")
Expand Down
2 changes: 1 addition & 1 deletion spec/sass_compile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@

it 'throws an error for an unrecognized style' do
expect { described_class.compile_string('a {b: c}', style: 'unrecognized style') }
.to raise_error(ArgumentError)
.to raise_error(defined?(RBS::Test::Tester::TypeError) ? RBS::Test::Tester::TypeError : ArgumentError)
end

it "doesn't throw a Sass exception for an argument error" do
Expand Down
12 changes: 6 additions & 6 deletions spec/sass_function_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
described_class.compile_string(
'a {b: foo(bar)}',
functions: {
'foo($arg)': fn
'foo($arg)': ->(args) { fn.call(args) }
}
).css
).to eq("a {\n b: \"result\";\n}")
Expand All @@ -35,7 +35,7 @@
described_class.compile_string(
'a {b: foo()}',
functions: {
'foo()': fn
'foo()': ->(args) { fn.call(args) }
}
).css
).to eq('')
Expand All @@ -57,7 +57,7 @@
described_class.compile_string(
'a {b: foo(x, y, z)}',
functions: {
'foo($arg1, $arg2, $arg3)': fn
'foo($arg1, $arg2, $arg3)': ->(args) { fn.call(args) }
}
).css
).to eq('')
Expand All @@ -77,7 +77,7 @@
described_class.compile_string(
'a {b: foo()}',
functions: {
'foo($arg: default)': fn
'foo($arg: default)': ->(args) { fn.call(args) }
}
).css
).to eq('')
Expand Down Expand Up @@ -142,7 +142,7 @@
described_class.compile_string(
'a {b: foo_bar()}',
functions: {
'foo-bar()': fn
'foo-bar()': ->(args) { fn.call(args) }
}
).css
).to eq('')
Expand All @@ -158,7 +158,7 @@
described_class.compile_string(
'a {b: foo-bar()}',
functions: {
'foo_bar()': fn
'foo_bar()': ->(args) { fn.call(args) }
}
).css
).to eq('')
Expand Down
2 changes: 1 addition & 1 deletion spec/sass_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def expect_from_import(canonicalize, expected)
"u:#{url}"
}
{
canonicalize:,
canonicalize: ->(*args) { canonicalize.call(*args) },
load: ->(*) { { contents: '', syntax: 'scss' } }
}
end
Expand Down
4 changes: 2 additions & 2 deletions spec/sass_proto_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def remote_eq(lhs, rhs)
described_class.compile_string(
'$_: foo(bar());',
functions: {
'foo($arg)': foo,
'bar()': bar
'foo($arg)': ->(args) { foo.call(args) },
'bar()': ->(args) { bar.call(args) }
}
).css
).to eq('')
Expand Down

0 comments on commit aade8c8

Please sign in to comment.