Sha256: 0c0d4b328ecc75940e3a965b754ce5b3df4530b8fa5b769a53efab1d73e57a41

Contents?: true

Size: 1.42 KB

Versions: 10

Compression:

Stored size: 1.42 KB

Contents

# coding: utf-8
require 'spec_helper'

describe 'Pattern Scanner' do
  describe 'scan_file' do
    it 'returns absolute keys from controllers' do
      file_path = 'spec/fixtures/app/controllers/events_controller.rb'
      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\")"}
           }
         ]
      )
    end
  end

  describe 'default_pattern' do
    let!(:pattern) { I18n::Tasks::Scanners::PatternScanner.new.default_pattern }

    [
      't(".a.b")',
      't "a.b"',
      "t 'a.b'",
      't("a.b")',
      "t('a.b')",
      "t('a.b', :arg => val)",
      "t('a.b', arg: val)",
      "t :a_b",
      "t :'a.b'",
      't :"a.b"',
      "t(:ab)",
      "t(:'a.b')",
      't(:"a.b")',
      'I18n.t("a.b")',
      'I18n.translate("a.b")'
    ].each do |string|
      it "matches #{string}" do
        expect(pattern).to match string
      end
    end

    ["t \"a.b'", "t a.b"].each do |string|
      it "does not match #{string}" do
        expect(pattern).to_not match string
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
i18n-tasks-0.8.5 spec/pattern_scanner_spec.rb
i18n-tasks-0.8.4 spec/pattern_scanner_spec.rb
i18n-tasks-0.8.3 spec/pattern_scanner_spec.rb
i18n-tasks-0.8.2 spec/pattern_scanner_spec.rb
i18n-tasks-0.8.1 spec/pattern_scanner_spec.rb
i18n-tasks-0.8.0 spec/pattern_scanner_spec.rb
i18n-tasks-0.7.13 spec/pattern_scanner_spec.rb
i18n-tasks-0.7.12 spec/pattern_scanner_spec.rb
i18n-tasks-0.7.11 spec/pattern_scanner_spec.rb
i18n-tasks-0.7.10 spec/pattern_scanner_spec.rb