diff --git a/spec/i18n_tasks_spec.rb b/spec/i18n_tasks_spec.rb index 16b2488b..40ee5968 100644 --- a/spec/i18n_tasks_spec.rb +++ b/spec/i18n_tasks_spec.rb @@ -22,7 +22,7 @@ expect(err).to include('greet') }, proc { - expect(%x[../../bin/i18n-tasks --version].chomp).to eq(I18n::Tasks::VERSION) + expect(%x[bundle exec ../../bin/i18n-tasks --version].chomp).to eq(I18n::Tasks::VERSION) } ].map { |test| Thread.start(&test) }.each(&:join) end diff --git a/spec/pattern_scanner_spec.rb b/spec/pattern_scanner_spec.rb index ca3e3d42..5bbe7f8f 100644 --- a/spec/pattern_scanner_spec.rb +++ b/spec/pattern_scanner_spec.rb @@ -2,25 +2,25 @@ RSpec.describe 'Pattern Scanner' do describe 'scan_file' do + let(:expected_key) { + 'events.show.success' + } + + let(:expected_data) { + {src_path: 'spec/fixtures/app/controllers/events_controller.rb', + pos: 774, + line_num: 33, + line_pos: 10, + line: ' I18n.t(".success")'} + } + it 'returns absolute keys from controllers' do file_path = 'spec/fixtures/app/controllers/events_controller.rb' - scanner = I18n::Tasks::Scanners::PatternScanner.new + scanner = I18n::Tasks::Scanners::PatternScanner.new allow(scanner).to receive(:relative_roots).and_return(['spec/fixtures/app/controllers']) - - keys = scanner.scan_file(file_path) - - expect(keys).to include( - ["events.show.success", - {:data=> - { - :src_path=>"spec/fixtures/app/controllers/events_controller.rb", - :pos=>790, - :line_num=>34, - :line_pos=>10, - :line =>" I18n.t(\".success\")"} - } - ] - ) + found_key = scanner.scan_file(file_path).detect { |key| key[0] == expected_key } + expect(found_key).to_not be_nil + expect(found_key).to eq [expected_key, data: expected_data] end end diff --git a/spec/support/trees.rb b/spec/support/trees.rb index c1aafd88..c96eb283 100644 --- a/spec/support/trees.rb +++ b/spec/support/trees.rb @@ -1,14 +1,24 @@ module Trees def expect_node_key_data(node, key, data) expect(node.full_key(root: false)).to eq key + expect(node.data).to eq adjust_source_occurrences(data) + end + + # adjust position to account for \r on Windows + def adjust_source_occurrences(data) if Gem.win_platform? - # adjust position to account for \r on Windows data = data.dup - data[:source_occurrences].map! { |occ| occ.dup.tap { |o| o[:pos] += o[:line_num] - 1 } } + data[:source_occurrences].map! { |occ| adjust_source_occurrence occ } end - expect(node.data).to eq data + data end + # adjust position to account for \r on Windows + def adjust_source_occurrence(occurrence) + occurrence.dup.tap { |o| o[:pos] += o[:line_num] - 1 } + end + + def build_tree(hash) I18n::Tasks::Data::Tree::Siblings.from_nested_hash(hash) end