Sha256: 18e1a32f936d6176be8c853978d8fbe16cb1dbc339e228b9c9376a59b6ed3b69

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

require 'dry/system/magic_comments_parser'

RSpec.describe Dry::System::MagicCommentsParser, '.call' do
  let(:file_name) { SPEC_ROOT.join('fixtures/magic_comments/comments.rb') }
  let(:comments) { described_class.(file_name) }

  it 'makes comment names available as symbols' do
    expect(comments.key?(:valid_comment)).to eql true
  end

  it 'finds magic comments after other commented lines or blank lines' do
    expect(comments[:valid_comment]).to eq 'hello'
  end

  it 'does not match comments with invalid names' do
    expect(comments.values).not_to include 'value for comment using dashes'
  end

  it 'supports comment names with alpha-numeric characters and underscores (numbers not allowed for first character)' do
    expect(comments[:comment_123]).to eq 'alpha-numeric and underscores allowed'
    expect(comments.keys).not_to include(:"123_will_not_match")
  end

  it 'only matches comments at the start of the line' do
    expect(comments.key?(:not_at_start_of_line)).to eql false
  end

  it 'does not match any comments after any lines of code' do
    expect(comments.key?(:after_code)).to eql false
  end

  describe 'coercions' do
    it 'coerces "true" to true' do
      expect(comments[:true_comment]).to eq true
    end

    it 'coerces "false" to false' do
      expect(comments[:false_comment]).to eq false
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-system-0.7.3 spec/unit/magic_comments_parser_spec.rb
dry-system-0.7.2 spec/unit/magic_comments_parser_spec.rb
dry-system-0.7.1 spec/unit/magic_comments_parser_spec.rb
dry-system-0.7.0 spec/unit/magic_comments_parser_spec.rb