Sha256: 3b7298e14c7fc9fcd533d37b1433842e5a9d4d971162acf8d86ca9937034d6df

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'

module Synvert::Core
  RSpec.describe Utils do
    describe '.eval_snippet' do
      it 'evals snippet by http url' do
        expect_any_instance_of(URI).to receive(:open).and_return(StringIO.new("Rewriter.new 'group', 'name' do\nend"))
        rewriter = described_class.eval_snippet('http://example.com/rewriter.rb')
        expect(rewriter.group).to eq 'group'
        expect(rewriter.name).to eq 'name'
      end

      it 'adds snippet by file path' do
        expect(File).to receive(:exist?).and_return(true)
        expect(File).to receive(:read).and_return("Rewriter.new 'group', 'name' do\nend")
        rewriter = described_class.eval_snippet('/home/richard/foo/bar.rb')
        expect(rewriter.group).to eq 'group'
        expect(rewriter.name).to eq 'name'
      end

      it 'adds snippet by snippet name' do
        expect(File).to receive(:exist?).and_return(false)
        expect(File).to receive(:read).and_return("Rewriter.new 'group', 'name' do\nend")
        rewriter = described_class.eval_snippet('/home/richard/foo/bar.rb')
        expect(rewriter.group).to eq 'group'
        expect(rewriter.name).to eq 'name'
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
synvert-core-1.14.2 spec/synvert/core/utils_spec.rb
synvert-core-1.14.1 spec/synvert/core/utils_spec.rb
synvert-core-1.14.0 spec/synvert/core/utils_spec.rb
synvert-core-1.13.1 spec/synvert/core/utils_spec.rb
synvert-core-1.13.0 spec/synvert/core/utils_spec.rb
synvert-core-1.12.0 spec/synvert/core/utils_spec.rb
synvert-core-1.11.0 spec/synvert/core/utils_spec.rb
synvert-core-1.10.1 spec/synvert/core/utils_spec.rb
synvert-core-1.10.0 spec/synvert/core/utils_spec.rb