spec/docstring_spec.rb in yard-0.8.7.6 vs spec/docstring_spec.rb in yard-0.9.0
- old
+ new
@@ -1,322 +1,329 @@
require File.dirname(__FILE__) + '/spec_helper'
describe YARD::Docstring do
before { YARD::Registry.clear }
- describe '#initialize' do
- it "should handle docstrings with empty newlines" do
- Docstring.new("\n\n").should == ""
+ describe "#initialize" do
+ it "handles docstrings with empty newlines" do
+ expect(Docstring.new("\n\n")).to eq ""
end
end
- describe '#+' do
- it "should add another Docstring" do
+ describe "#+" do
+ it "adds another Docstring" do
d = Docstring.new("FOO") + Docstring.new("BAR")
- d.should == "FOO\nBAR"
+ expect(d).to eq "FOO\nBAR"
end
- it "should copy over tags" do
+ it "copies over tags" do
d1 = Docstring.new("FOO\n@api private\n")
d2 = Docstring.new("BAR\n@param foo descr")
d = (d1 + d2)
- d.should have_tag(:api)
- d.should have_tag(:param)
+ expect(d).to have_tag(:api)
+ expect(d).to have_tag(:param)
end
- it "should add a String" do
+ it "adds a String" do
d = Docstring.new("FOO") + "BAR"
- d.should == "FOOBAR"
+ expect(d).to eq "FOOBAR"
end
end
- describe '#line' do
- it "should return nil if #line_range is not set" do
- Docstring.new('foo').line.should be_nil
+ describe "#line" do
+ it "returns nil if #line_range is not set" do
+ expect(Docstring.new('foo').line).to be nil
end
- it "should return line_range.first if #line_range is set" do
+ it "returns line_range.first if #line_range is set" do
doc = Docstring.new('foo')
doc.line_range = (1..10)
- doc.line.should == doc.line_range.first
+ expect(doc.line).to eq doc.line_range.first
end
end
- describe '#summary' do
- it "should handle empty docstrings" do
+ describe "#summary" do
+ it "handles empty docstrings" do
o1 = Docstring.new
- o1.summary.should == ""
+ expect(o1.summary).to eq ""
end
- it "should handle multiple calls" do
+ it "handles multiple calls" do
o1 = Docstring.new("Hello. world")
- 5.times { o1.summary.should == "Hello." }
+ 5.times { expect(o1.summary).to eq "Hello." }
end
- it "should strip HTML before summarizing" do
+ it "strips HTML before summarizing" do
doc = Docstring.new("<p>Hello <b>world</b></p>.")
- doc.summary.should == 'Hello world.'
+ expect(doc.summary).to eq 'Hello world.'
end
- it "should strip newlines in first paragraph before summarizing" do
+ it "strips newlines in first paragraph before summarizing" do
doc = Docstring.new("Foo\n<code>==</code> bar.")
- doc.summary.should == 'Foo == bar.'
+ expect(doc.summary).to eq 'Foo == bar.'
end
- it "should return the first sentence" do
+ it "returns the first sentence" do
o = Docstring.new("DOCSTRING. Another sentence")
- o.summary.should == "DOCSTRING."
+ expect(o.summary).to eq "DOCSTRING."
end
- it "should return the first paragraph" do
+ it "returns the first paragraph" do
o = Docstring.new("DOCSTRING, and other stuff\n\nAnother sentence.")
- o.summary.should == "DOCSTRING, and other stuff."
+ expect(o.summary).to eq "DOCSTRING, and other stuff."
end
- it "should return proper summary when docstring is changed" do
+ it "returns proper summary when docstring is changed" do
o = Docstring.new "DOCSTRING, and other stuff\n\nAnother sentence."
- o.summary.should == "DOCSTRING, and other stuff."
+ expect(o.summary).to eq "DOCSTRING, and other stuff."
o = Docstring.new "DOCSTRING."
- o.summary.should == "DOCSTRING."
+ expect(o.summary).to eq "DOCSTRING."
end
- it "should not double the ending period" do
+ it "does not double the ending period" do
o = Docstring.new("Returns a list of tags specified by +name+ or all tags if +name+ is not specified.\n\nTest")
- o.summary.should == "Returns a list of tags specified by +name+ or all tags if +name+ is not specified."
+ expect(o.summary).to eq "Returns a list of tags specified by +name+ or all tags if +name+ is not specified."
doc = Docstring.new(<<-eof)
Returns a list of tags specified by +name+ or all tags if +name+ is not specified.
@param name the tag name to return data for, or nil for all tags
@return [Array<Tags::Tag>] the list of tags by the specified tag name
eof
- doc.summary.should == "Returns a list of tags specified by +name+ or all tags if +name+ is not specified."
+ expect(doc.summary).to eq "Returns a list of tags specified by +name+ or all tags if +name+ is not specified."
end
- it "should not attach period if entire summary is include" do
+ it "does not attach period if entire summary is include" do
YARD.parse_string "# docstring\ndef foo; end"
- Docstring.new("{include:#foo}").summary.should == '{include:#foo}'
+ expect(Docstring.new("{include:#foo}").summary).to eq '{include:#foo}'
Registry.clear
end
- it "should handle references embedded in summary" do
- Docstring.new("Aliasing {Test.test}. Done.").summary.should == "Aliasing {Test.test}."
+ it "handles references embedded in summary" do
+ expect(Docstring.new("Aliasing {Test.test}. Done.").summary).to eq "Aliasing {Test.test}."
end
- it "should only end first sentence when outside parentheses" do
- Docstring.new("Hello (the best.) world. Foo bar.").summary.should == "Hello (the best.) world."
- Docstring.new("A[b.]c.").summary.should == "A[b.]c."
+ it "only ends first sentence when outside parentheses" do
+ expect(Docstring.new("Hello (the best.) world. Foo bar.").summary).to eq "Hello (the best.) world."
+ expect(Docstring.new("A[b.]c.").summary).to eq "A[b.]c."
end
- it "should only see '.' as period if whitespace (or eof) follows" do
- Docstring.new("hello 1.5 times.").summary.should == "hello 1.5 times."
- Docstring.new("hello... me").summary.should == "hello..."
- Docstring.new("hello.").summary.should == "hello."
+ it "only sees '.' as period if whitespace (or eof) follows" do
+ expect(Docstring.new("hello 1.5 times.").summary).to eq "hello 1.5 times."
+ expect(Docstring.new("hello... me").summary).to eq "hello..."
+ expect(Docstring.new("hello.").summary).to eq "hello."
end
+
+ it "returns summary if there is a newline and parentheses count doesn't match" do
+ expect(Docstring.new("Happy method call :-)\n\nCall any time.").summary).to eq "Happy method call :-)."
+ expect(Docstring.new("Sad method call :-(\n\nCall any time.").summary).to eq "Sad method call :-(."
+ expect(Docstring.new("Hello (World. Forget to close.\n\nNew text").summary).to eq "Hello (World. Forget to close."
+ expect(Docstring.new("Hello (World. Forget to close\n\nNew text").summary).to eq "Hello (World. Forget to close."
+ end
end
- describe '#ref_tags' do
- it "should parse reference tag into ref_tags" do
+ describe "#ref_tags" do
+ it "parses reference tag into ref_tags" do
doc = Docstring.new("@return (see Foo#bar)")
- doc.ref_tags.size.should == 1
- doc.ref_tags.first.owner.should == P("Foo#bar")
- doc.ref_tags.first.tag_name.should == "return"
- doc.ref_tags.first.name.should be_nil
+ expect(doc.ref_tags.size).to eq 1
+ expect(doc.ref_tags.first.owner).to eq P("Foo#bar")
+ expect(doc.ref_tags.first.tag_name).to eq "return"
+ expect(doc.ref_tags.first.name).to be nil
end
- it "should parse named reference tag into ref_tags" do
+ it "parses named reference tag into ref_tags" do
doc = Docstring.new("@param blah \n (see Foo#bar )")
- doc.ref_tags.size.should == 1
- doc.ref_tags.first.owner.should == P("Foo#bar")
- doc.ref_tags.first.tag_name.should == "param"
- doc.ref_tags.first.name.should == "blah"
+ expect(doc.ref_tags.size).to eq 1
+ expect(doc.ref_tags.first.owner).to eq P("Foo#bar")
+ expect(doc.ref_tags.first.tag_name).to eq "param"
+ expect(doc.ref_tags.first.name).to eq "blah"
end
- it "should fail to parse named reference tag into ref_tags" do
+ it "fails to parse named reference tag into ref_tags" do
doc = Docstring.new("@param blah THIS_BREAKS_REFTAG (see Foo#bar)")
- doc.ref_tags.size.should == 0
+ expect(doc.ref_tags.size).to eq 0
end
- it "should return all valid reference tags along with #tags" do
+ it "returns all valid reference tags along with #tags" do
o = CodeObjects::MethodObject.new(:root, 'Foo#bar')
o.docstring.add_tag Tags::Tag.new('return', 'testing')
doc = Docstring.new("@return (see Foo#bar)")
tags = doc.tags
- tags.size.should == 1
- tags.first.text.should == 'testing'
- tags.first.should be_kind_of(Tags::RefTag)
- tags.first.owner.should == o
+ expect(tags.size).to eq 1
+ expect(tags.first.text).to eq 'testing'
+ expect(tags.first).to be_kind_of(Tags::RefTag)
+ expect(tags.first.owner).to eq o
end
- it "should return all valid named reference tags along with #tags(name)" do
+ it "returns all valid named reference tags along with #tags(name)" do
o = CodeObjects::MethodObject.new(:root, 'Foo#bar')
o.docstring.add_tag Tags::Tag.new('param', 'testing', nil, '*args')
o.docstring.add_tag Tags::Tag.new('param', 'NOTtesting', nil, 'notargs')
doc = Docstring.new("@param *args (see Foo#bar)")
tags = doc.tags('param')
- tags.size.should == 1
- tags.first.text.should == 'testing'
- tags.first.should be_kind_of(Tags::RefTag)
- tags.first.owner.should == o
+ expect(tags.size).to eq 1
+ expect(tags.first.text).to eq 'testing'
+ expect(tags.first).to be_kind_of(Tags::RefTag)
+ expect(tags.first.owner).to eq o
end
- it "should ignore invalid reference tags" do
+ it "ignores invalid reference tags" do
doc = Docstring.new("@param *args (see INVALID::TAG#tag)")
tags = doc.tags('param')
- tags.size.should == 0
+ expect(tags.size).to eq 0
end
it "resolves references to methods in the same class with #methname" do
klass = CodeObjects::ClassObject.new(:root, "Foo")
o = CodeObjects::MethodObject.new(klass, "bar")
ref = CodeObjects::MethodObject.new(klass, "baz")
o.docstring.add_tag Tags::Tag.new('param', 'testing', nil, 'arg1')
ref.docstring = "@param (see #bar)"
tags = ref.docstring.tags("param")
- tags.size.should == 1
- tags.first.text.should == "testing"
- tags.first.should be_kind_of(Tags::RefTag)
- tags.first.owner.should == o
+ expect(tags.size).to eq 1
+ expect(tags.first.text).to eq "testing"
+ expect(tags.first).to be_kind_of(Tags::RefTag)
+ expect(tags.first.owner).to eq o
end
end
- describe '#empty?/#blank?' do
+ describe "#empty?/#blank?" do
before(:all) do
Tags::Library.define_tag "Invisible", :invisible_tag
end
- it "should be blank and empty if it has no content and no tags" do
- Docstring.new.should be_blank
- Docstring.new.should be_empty
+ it "is blank and empty if it has no content and no tags" do
+ expect(Docstring.new).to be_blank
+ expect(Docstring.new).to be_empty
end
- it "shouldn't be empty or blank if it has content" do
+ it "isn't empty or blank if it has content" do
d = Docstring.new("foo bar")
- d.should_not be_empty
- d.should_not be_blank
+ expect(d).not_to be_empty
+ expect(d).not_to be_blank
end
- it "should be empty but not blank if it has tags" do
+ it "is empty but not blank if it has tags" do
d = Docstring.new("@param foo")
- d.should be_empty
- d.should_not be_blank
+ expect(d).to be_empty
+ expect(d).not_to be_blank
end
- it "should be empty but not blank if it has ref tags" do
+ it "is empty but not blank if it has ref tags" do
o = CodeObjects::MethodObject.new(:root, 'Foo#bar')
o.docstring.add_tag Tags::Tag.new('return', 'testing')
d = Docstring.new("@return (see Foo#bar)")
- d.should be_empty
- d.should_not be_blank
+ expect(d).to be_empty
+ expect(d).not_to be_blank
end
- it "should be blank if it has no visible tags" do
+ it "is blank if it has no visible tags" do
d = Docstring.new("@invisible_tag value")
- d.should be_blank
+ expect(d).to be_blank
end
- it "should not be blank if it has invisible tags and only_visible_tags = false" do
+ it "is not blank if it has invisible tags and only_visible_tags = false" do
d = Docstring.new("@invisible_tag value")
d.add_tag Tags::Tag.new('invisible_tag', nil, nil)
- d.blank?(false).should == false
+ expect(d.blank?(false)).to be false
end
end
- describe '#delete_tags' do
- it "should delete tags by a given tag name" do
+ describe "#delete_tags" do
+ it "deletes tags by a given tag name" do
doc = Docstring.new("@param name x\n@param name2 y\n@return foo")
doc.delete_tags(:param)
- doc.tags.size.should == 1
+ expect(doc.tags.size).to eq 1
end
end
- describe '#delete_tag_if' do
- it "should delete tags for a given block" do
+ describe "#delete_tag_if" do
+ it "deletes tags for a given block" do
doc = Docstring.new("@param name x\n@param name2 y\n@return foo")
doc.delete_tag_if {|t| t.name == 'name2' }
- doc.tags.size.should == 2
+ expect(doc.tags.size).to eq 2
end
end
- describe '#to_raw' do
- it "should return a clean representation of tags" do
+ describe "#to_raw" do
+ it "returns a clean representation of tags" do
doc = Docstring.new("Hello world\n@return [String, X] foobar\n@param name<Array> the name\nBYE!")
- doc.to_raw.should == "Hello world\nBYE!\n@param [Array] name\n the name\n@return [String, X] foobar"
+ expect(doc.to_raw).to eq "Hello world\nBYE!\n@param [Array] name\n the name\n@return [String, X] foobar"
end
- it "should handle tags with newlines and indentation" do
+ it "handles tags with newlines and indentation" do
doc = Docstring.new("@example TITLE\n the \n example\n @foo\n@param [X] name\n the name")
- doc.to_raw.should == "@example TITLE\n the \n example\n @foo\n@param [X] name\n the name"
+ expect(doc.to_raw).to eq "@example TITLE\n the \n example\n @foo\n@param [X] name\n the name"
end
- it "should handle deleted tags" do
+ it "handles deleted tags" do
doc = Docstring.new("@example TITLE\n the \n example\n @foo\n@param [X] name\n the name")
doc.delete_tags(:param)
- doc.to_raw.should == "@example TITLE\n the \n example\n @foo"
+ expect(doc.to_raw).to eq "@example TITLE\n the \n example\n @foo"
end
- it "should handle added tags" do
+ it "handles added tags" do
doc = Docstring.new("@example TITLE\n the \n example\n @foo")
doc.add_tag(Tags::Tag.new('foo', 'foo'))
- doc.to_raw.should == "@example TITLE\n the \n example\n @foo\n@foo foo"
+ expect(doc.to_raw).to eq "@example TITLE\n the \n example\n @foo\n@foo foo"
end
- it "should be equal to .all if not modified" do
+ it "is equal to .all if not modified" do
doc = Docstring.new("123\n@param")
- doc.to_raw.should == doc.all
+ expect(doc.to_raw).to eq doc.all
end
# @bug gh-563
- it "should handle full @option tags" do
+ it "handles full @option tags" do
doc = Docstring.new("@option foo [String] bar (nil) baz")
- doc.to_raw.should == "@option foo [String] bar (nil) baz"
+ expect(doc.to_raw).to eq "@option foo [String] bar (nil) baz"
end
# @bug gh-563
- it "should handle simple @option tags" do
+ it "handles simple @option tags" do
doc = Docstring.new("@option foo :key bar")
- doc.to_raw.should == "@option foo :key bar"
+ expect(doc.to_raw).to eq "@option foo :key bar"
end
end
- describe '#dup' do
- it "should duplicate docstring text" do
+ describe "#dup" do
+ it "duplicates docstring text" do
doc = Docstring.new("foo")
- doc.dup.should == doc
- doc.dup.all.should == doc
+ expect(doc.dup).to eq doc
+ expect(doc.dup.all).to eq doc
end
- it "should duplicate tags to new list" do
+ it "duplicates tags to new list" do
doc = Docstring.new("@param x\n@return y")
doc2 = doc.dup
doc2.delete_tags(:param)
- doc.tags.size.should == 2
- doc2.tags.size.should == 1
+ expect(doc.tags.size).to eq 2
+ expect(doc2.tags.size).to eq 1
end
- it "should preserve summary" do
+ it "preserves summary" do
doc = Docstring.new("foo. bar")
- doc.dup.summary.should == doc.summary
+ expect(doc.dup.summary).to eq doc.summary
end
- it "should preserve hash_flag" do
+ it "preserves hash_flag" do
doc = Docstring.new
doc.hash_flag = 'foo'
- doc.dup.hash_flag.should == doc.hash_flag
+ expect(doc.dup.hash_flag).to eq doc.hash_flag
end
- it "should preserve line_range" do
+ it "preserves line_range" do
doc = Docstring.new
doc.line_range = (1..2)
- doc.dup.line_range.should == doc.line_range
+ expect(doc.dup.line_range).to eq doc.line_range
end
end
- describe 'reference docstrings' do
- it 'allows for construction of docstring with ref object' do
+ describe "reference docstrings" do
+ it "allows for construction of docstring with ref object" do
YARD.parse_string <<-eof
class A
# Docstring
# @return [Boolean]
def a; end
@@ -324,11 +331,11 @@
def b; end
end
eof
object = YARD::Registry.at('A#b')
- object.docstring.should == 'Docstring'
- object.tags.map {|x| x.tag_name }.should == ['return']
+ expect(object.docstring).to eq 'Docstring'
+ expect(object.tags.map {|x| x.tag_name }).to eq ['return']
YARD::Registry.clear
end
end
end