-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore keys in views with non-literal scope arg
Fixes #213
- Loading branch information
Showing
3 changed files
with
98 additions
and
12 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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'PatternWithScopeScanner' do | ||
def stub_source(scanner, source) | ||
allow(scanner).to receive(:traverse_files) { |&block| [block.call('test')] } | ||
allow(scanner).to receive(:read_file) { source } | ||
end | ||
|
||
describe 'match_to_key' do | ||
let(:scanner) do | ||
I18n::Tasks::Scanners::PatternWithScopeScanner.new | ||
end | ||
|
||
it 'matches a literal scope' do | ||
stub_source scanner, '= t :key, scope: "scope"' | ||
expect(scanner.keys.map(&:key)).to eq(['scope.key']) | ||
|
||
stub_source scanner, '= t :key, scope: :scope' | ||
expect(scanner.keys.map(&:key)).to eq(['scope.key']) | ||
|
||
stub_source scanner, '= t :key, :scope => :scope' | ||
expect(scanner.keys.map(&:key)).to eq(['scope.key']) | ||
|
||
stub_source scanner, '= t :key, :scope => :scope, default: "Default"' | ||
expect(scanner.keys.map(&:key)).to eq(['scope.key']) | ||
end | ||
|
||
it 'matches an array of literals scope' do | ||
stub_source scanner, '= t :key, :scope => [:a, :b]' | ||
expect(scanner.keys.map(&:key)).to eq(['a.b.key']) | ||
end | ||
|
||
it 'does not match anything else' do | ||
stub_source scanner, '= t :key, scope: a' | ||
expect(scanner.keys.map(&:key)).to eq([]) | ||
|
||
stub_source scanner, '= t :key, scope: []' | ||
expect(scanner.keys.map(&:key)).to eq([]) | ||
|
||
stub_source scanner, '= t :key, scope: [a]' | ||
expect(scanner.keys.map(&:key)).to eq([]) | ||
|
||
stub_source scanner, '= t :key, scope: [:x, [:y]]' | ||
expect(scanner.keys.map(&:key)).to eq([]) | ||
|
||
stub_source scanner, '= t :key, scope: (a)' | ||
expect(scanner.keys.map(&:key)).to eq([]) | ||
end | ||
|
||
it 'matches only the scope argument' do | ||
stub_source scanner, '= t :key, :scope => [:a, :b] :c' | ||
expect(scanner.keys.map(&:key)).to eq(['a.b.key']) | ||
|
||
stub_source scanner, '= t :key, :scope => [:a, :b], :c' | ||
expect(scanner.keys.map(&:key)).to eq(['a.b.key']) | ||
end | ||
end | ||
end |