Sha256: 45e64cbd699409d306e91863098a8bb290bd482d1bf4ccbc5a4bb789ab619afc

Contents?: true

Size: 1.51 KB

Versions: 40

Compression:

Stored size: 1.51 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'

describe SourceCode, 'Rubyのソースコードを表現するモデル' do
  describe 'validation' do
    describe 'filename' do
      specify 'ディレクトリセパレータを含むことはできない' do
        sc = SourceCode.new(filename: '/etc/passwd')
        expect(sc).not_to be_valid
        expect(sc.errors[:filename])
          .to include('includes directory separator(s)')
      end
    end
  end

  describe '#check_syntax', 'シンタックスをチェックする' do
    let(:source_code) {
      SourceCode.new(data: data)
    }

    subject { source_code.check_syntax }

    context 'シンタックスが正しい場合' do
      let(:data) { 'puts "Hello, World!"' }

      it { should be_empty }
    end

    context 'シンタックスが正しくない場合' do
      let(:data) { 'puts Hello, World!"' }

      it { should_not be_empty }
      it {
        should include(row: 1, column: 19,
                       message: 'syntax error, unexpected tSTRING_BEG,' \
                       " expecting keyword_do or '{' or '('")
      }
      it {
        should include(row: 1, column: 0,
                       message: 'unterminated string meets end of file')
      }
    end
  end

  describe '#digest', 'プログラムのハッシュ値を計算する' do
    let(:data) { 'puts "Hello, World!"' }
    let(:source_code) {
      SourceCode.new(data: data)
    }

    subject { source_code.digest }

    it { should eq(Digest::SHA256.hexdigest(data)) }
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
smalruby-editor-0.1.4 spec/models/source_code_spec.rb
smalruby-editor-0.1.3-x86-mingw32 spec/models/source_code_spec.rb
smalruby-editor-0.1.3 spec/models/source_code_spec.rb
smalruby-editor-0.1.2-x86-mingw32 spec/models/source_code_spec.rb
smalruby-editor-0.1.2 spec/models/source_code_spec.rb
smalruby-editor-0.1.1-x86-mingw32 spec/models/source_code_spec.rb
smalruby-editor-0.1.1 spec/models/source_code_spec.rb
smalruby-editor-0.1.0-x86-mingw32 spec/models/source_code_spec.rb
smalruby-editor-0.1.0 spec/models/source_code_spec.rb
smalruby-editor-0.0.12-x86-mingw32 spec/models/source_code_spec.rb
smalruby-editor-0.0.12 spec/models/source_code_spec.rb
smalruby-editor-0.0.11-x86-mingw32 spec/models/source_code_spec.rb
smalruby-editor-0.0.11 spec/models/source_code_spec.rb
smalruby-editor-0.0.10-x86-mingw32 spec/models/source_code_spec.rb
smalruby-editor-0.0.10 spec/models/source_code_spec.rb
smalruby-editor-0.0.9-x86-mingw32 spec/models/source_code_spec.rb
smalruby-editor-0.0.9 spec/models/source_code_spec.rb
smalruby-editor-0.0.8 spec/models/source_code_spec.rb
smalruby-editor-0.0.8-x86-mingw32 spec/models/source_code_spec.rb
smalruby-editor-0.0.7 spec/models/source_code_spec.rb