require 'spec_helper' EXAMPLE_DOC_DIR=[File.expand_path(File.dirname(__FILE__) + "/fixtures/*.rb"), File.expand_path(File.dirname(__FILE__) + "/*.rb")] describe "Using the rspec_example tag in the method comment" do before(:each) do YARD.parse(EXAMPLE_DOC_DIR) foo = YARD::Registry.all(:class).find { |i| i.to_s == "Foo" } @class_foo_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => foo)) bar = YARD::Registry.all(:class).find { |i| i.to_s == "Foo::Bar" } @class_bar_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => bar)) nested_class = YARD::Registry.all(:class).find { |i| i.to_s == "My::Nested::Class" } @nested_class_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => nested_class)) end it "spawns no warnings on the fixtures" do expect do YARD.parse(EXAMPLE_DOC_DIR) foo = YARD::Registry.all(:class).find { |i| i.to_s == "Foo" } @class_foo_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => foo)) bar = YARD::Registry.all(:class).find { |i| i.to_s == "Foo::Bar" } @class_bar_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => bar)) nested_class = YARD::Registry.all(:module).find { |i| i.to_s == "My" } @nested_class_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => nested_class)) end.not_to output.to_stdout end it "displays warning on unfound example" do expect do invalid_class = YARD::Registry.all(:class).find { |i| i.to_s == "InvalidClass" } @invalid_class_output = YARD::Templates::Engine.render(OPTIONS.merge(:object => invalid_class)) end.to output("[warn] Could not find example 'InvalidClass#some_method invalid'\n").to_stdout end it "creates an example tag in the registry" do expect(@class_foo_output).to match /Examples:/ end it "outputs the source code of the example of a method that reads \"works this way\" " do expect(@class_foo_output).to match /this/ end it "includes the comments in the example as well" do expect(@class_foo_output).to match /With some comments/ end it "supports single line do begin" do expect(Nokogiri.HTML(@class_foo_output).css('.examples .example').map(&:text)).to include('"abracadabra"') end it "supports curly braces syntax" do expect(Nokogiri.HTML(@class_foo_output).css('.examples .example').map(&:text)).to include('"curly braces"') end it "works with nested classes" do expect(@class_bar_output).to match /nested_class/ end it "works with module/class/class nestes classes" do expect(@nested_class_output).to match /super_nested_class/ end it "includes named examples" do expect(@class_foo_output).to include CGI.escape_html("comment for 'also support this' it") end end # A bit of a hack, this is the spec that is going to be used as fixture for the plugin describe Foo do context "#foo_method" do it "works this way" do # With some comments end it "also supports this" do # comment for 'also support this' it end it "supports single line do begin" do; "abracadabra" end it("supports curly braces syntax"){"curly braces"} end end describe Foo::Bar do describe "#bar_method" do it "works this way" do nested_class = nil end end describe ".class_method" do it 'is defined' do Foo::Bar.class_method end end end module My describe Nested::Class do describe "#nested_method" do it "works this way" do super_nested_class = nil end end end end