Sha256: dfe2a2771b73785dc921231d5297a54298ad643f75ef8d6c40dadb5d6543c693

Contents?: true

Size: 1.97 KB

Versions: 22

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require 'test_helper'

module Vedeu

  module Coercers

    describe EditorLines do

      let(:described) { Vedeu::Coercers::EditorLines }
      let(:instance)  { described.new(_value) }
      let(:_value)    {}
      let(:klass)     { Vedeu::Editor::Lines }

      describe '#initialize' do
        it { instance.must_be_instance_of(described) }
        it { instance.instance_variable_get('@value').must_equal(_value) }
      end

      describe '.coerce' do
        it { described.must_respond_to(:coerce) }
      end

      describe '#coerce' do
        subject { instance.coerce }

        context 'when the value is already the target class' do
          let(:_value) { klass.new }

          it { subject.must_be_instance_of(klass) }
          it { subject.must_equal(_value) }
        end

        context 'when the value is an Array' do
          context 'when the value is empty' do
            let(:_value) { [] }

            it { subject.collection.must_equal([]) }
          end

          context 'when the value is not empty' do
            let(:_value) {
              [
                Vedeu::Editor::Line.new('Some text...'),
                :more_text,
                'Other text...',
              ]
            }
            let(:expected) {
              [
                Vedeu::Editor::Line.new('Some text...'),
                Vedeu::Editor::Line.new(''),
                Vedeu::Editor::Line.new('Other text...'),
              ]
            }

            it { subject.collection.must_equal(expected) }
          end
        end

        context 'when the value is a String' do
          let(:_value) { "Some text...\nMore text..." }

          context 'but it is empty' do
            let(:_value) { '' }

            it { subject.must_equal(Vedeu::Editor::Lines.new) }
          end

          context 'but it has no line breaks' do
            # @todo Add more tests.
          end
        end
      end

    end # EditorLines

  end # Coercers

end # Vedeu

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
vedeu-0.8.32 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.31 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.30 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.29 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.28 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.27 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.26 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.25 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.24 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.23 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.22 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.21 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.20 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.19 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.18 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.17 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.16 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.15 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.14 test/lib/vedeu/coercers/editor_lines_test.rb
vedeu-0.8.13 test/lib/vedeu/coercers/editor_lines_test.rb