1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
require 'spec_helper'
describe StringDirection::MarksStrategy do
describe '#run' do
subject { described_class.new.run(string) }
context 'when string contains the left-to-right mark but not the right-to-left mark' do
let(:string) { described_class::LTR_MARK + 'abc' }
it "returns 'ltr'" do
expect(subject).to eql 'ltr'
end
end
context 'when string contains the right-to-left mark but not the left-to-right mark' do
let(:string) { described_class::RTL_MARK + 'abc' }
it "returns 'rtl'" do
expect(subject).to eql 'rtl'
end
end
context 'when string contains both the left-to-right mark and the right-to-left mark' do
let(:string) { described_class::LTR_MARK + described_class::RTL_MARK + 'abc' }
it "returns 'bidi'" do
expect(subject).to eql 'bidi'
end
end
context 'when string neither contains the left-to-right mark nor the right-to-left mark' do
let(:string) { 'abc' }
it "returns nil" do
expect(subject).to be_nil
end
end
context 'when an object responding to #to_s is given' do
let(:string) do
class StringDirection::TestObject
def to_s
StringDirection::MarksStrategy::LTR_MARK
end
end
StringDirection::TestObject.new
end
it 'takes as string the result of #to_s method' do
expect(subject).to eq('ltr')
end
end
end
end
|