Skip to content

Commit

Permalink
Fix a failing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Aug 3, 2015
1 parent 03d84cb commit a17ca2c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion spec/i18n_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions spec/pattern_scanner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 13 additions & 3 deletions spec/support/trees.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a17ca2c

Please sign in to comment.