require 'spec_helper' SimpleCov.command_name('DocString') unless RUBY_VERSION.to_s < '1.9.0' describe 'DocString, Unit' do let(:clazz) { CukeModeler::DocString } let(:doc_string) { clazz.new } describe 'common behavior' do it_should_behave_like 'a nested element' it_should_behave_like 'a bare bones element' it_should_behave_like 'a prepopulated element' it_should_behave_like 'a raw element' end describe 'unique behavior' do it 'can be parsed from stand alone text' do source = "\"\"\"\nsome doc string\n\"\"\"" expect { @element = clazz.new(source) }.to_not raise_error # Sanity check in case instantiation failed in a non-explosive manner @element.contents_text.should == "some doc string" #todo Remove once Array contents is no longer supported @element.contents.should == ["some doc string"] end it 'provides a descriptive filename when being parsed from stand alone text' do source = 'bad doc string text' expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_doc_string\.feature'/) end it 'stores the original data generated by the parsing adapter', :gherkin4 => true do doc_string = clazz.new("\"\"\"\nsome doc string\n\"\"\"") raw_data = doc_string.raw_element expect(raw_data.keys).to match_array([:type, :location, :content]) expect(raw_data[:type]).to eq(:DocString) end it 'stores the original data generated by the parsing adapter', :gherkin3 => true do doc_string = clazz.new("\"\"\"\nsome doc string\n\"\"\"") raw_data = doc_string.raw_element expect(raw_data.keys).to match_array([:type, :location, :content]) expect(raw_data[:type]).to eq(:DocString) end it 'stores the original data generated by the parsing adapter', :gherkin2 => true do doc_string = clazz.new("\"\"\"\nsome doc string\n\"\"\"") raw_data = doc_string.raw_element expect(raw_data.keys).to match_array(['value', 'content_type', 'line']) expect(raw_data['value']).to eq('some doc string') end it 'has a content type' do doc_string.should respond_to(:content_type) end it 'can change its content type' do expect(doc_string).to respond_to(:content_type=) doc_string.content_type = :some_content_type doc_string.content_type.should == :some_content_type doc_string.content_type = :some_other_content_type doc_string.content_type.should == :some_other_content_type end it 'starts with no content type' do doc_string.content_type.should == nil end it 'has contents' do #todo Remove once Array contents is no longer supported doc_string.should respond_to(:contents) doc_string.should respond_to(:contents_text) end it 'can get and set its contents' do expect(doc_string).to respond_to(:contents=) expect(doc_string).to respond_to(:contents_text=) #todo Remove once Array contents is no longer supported doc_string.contents = :some_contents doc_string.contents.should == :some_contents doc_string.contents = :some_other_contents doc_string.contents.should == :some_other_contents doc_string.contents_text = :some_contents doc_string.contents_text.should == :some_contents doc_string.contents_text = :some_other_contents doc_string.contents_text.should == :some_other_contents end it 'starts with no contents' do #todo Remove once Array contents is no longer supported doc_string.contents.should == [] doc_string.contents_text.should == '' end #todo Remove once Array contents is no longer supported it 'stores its contents as an array of strings - deprecated' do source = "\"\"\"\nsome text\nsome more text\n\"\"\"" doc_string = clazz.new(source) contents = doc_string.contents contents.is_a?(Array).should be_true contents.each do |line| line.is_a?(String).should be_true end end it 'stores its contents as a String' do source = "\"\"\"\nsome text\nsome more text\n\"\"\"" doc_string = clazz.new(source) contents = doc_string.contents_text contents.is_a?(String).should be_true end describe 'doc string output edge cases' do it 'is a String' do doc_string.to_s.should be_a(String) end context 'a new doc string object' do let(:doc_string) { clazz.new } it 'can output an empty doc string' do expect { doc_string.to_s }.to_not raise_error end it 'can output a doc string that has only a content type' do doc_string.content_type = 'some type' expect { doc_string.to_s }.to_not raise_error end end end end end