Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix assigns in filters defined with Filter.define
- Loading branch information
Showing
2 changed files
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
describe Nanoc::Filter do | ||
describe '.define' do | ||
before do | ||
Nanoc::Filter.define(:nanoc_filter_define_sample) do |content, _params| | ||
content.upcase | ||
context 'simple filter' do | ||
let(:filter_name) { 'b5355bbb4d772b9853d21be57da614dba521dbbb' } | ||
let(:filter_class) { Nanoc::Filter.named(filter_name) } | ||
|
||
before do | ||
Nanoc::Filter.define(filter_name) do |content, _params| | ||
content.upcase | ||
end | ||
end | ||
end | ||
|
||
it 'defines a filter' do | ||
expect(Nanoc::Filter.named(:nanoc_filter_define_sample)).not_to be_nil | ||
it 'defines a filter' do | ||
expect(filter_class).not_to be_nil | ||
end | ||
|
||
it 'defines a callable filter' do | ||
expect(filter_class.new.run('foo', {})).to eql('FOO') | ||
end | ||
end | ||
|
||
it 'defines a callable filter' do | ||
expect(Nanoc::Filter.named(:nanoc_filter_define_sample).new.run('foo', {})).to eql('FOO') | ||
context 'filter that accesses assigns' do | ||
let(:filter_name) { 'd7ed105d460e99a3d38f46af023d9490c140fdd9' } | ||
let(:filter_class) { Nanoc::Filter.named(filter_name) } | ||
let(:filter) { filter_class.new(assigns) } | ||
let(:assigns) { { animal: 'Giraffe' } } | ||
|
||
before do | ||
Nanoc::Filter.define(filter_name) do |_content, _params| | ||
@animal | ||
end | ||
end | ||
|
||
it 'can access assigns' do | ||
expect(filter.setup_and_run(:__irrelevant__, {})).to eq('Giraffe') | ||
end | ||
end | ||
end | ||
end |