spec/cinch-toolbox_spec.rb in cinch-toolbox-1.0.1 vs spec/cinch-toolbox_spec.rb in cinch-toolbox-1.0.2

- old
+ new

@@ -3,27 +3,35 @@ describe Cinch::Toolbox do describe 'the get_html_element method' do before(:all) do + @fake_web_html = "<div id=\"a1\" class=\"top\">\n<div class=\"foo\">Bar</div>\n<div id=\"foo1\">Baz</div>\n</div>" FakeWeb.register_uri( :get, "http://example.com/", - :body => "<div id='a1' class='top'> - <div class='foo'>Bar</div> - <div id='foo1'>Baz</div> - </div>") + :body => @fake_web_html) end it 'should return a string with contents of a css selector of a web page' do Cinch::Toolbox.get_html_element('http://example.com/', '.foo', :css). should == 'Bar' end + it 'should return a string with full markup of a css selector of a web page' do + Cinch::Toolbox.get_html_element('http://example.com/', '.top', :css_full). + should == @fake_web_html + end + it 'should return a string with contents of a xpath selector of a web page' do Cinch::Toolbox.get_html_element('http://example.com/', "//div/div[1]", :xpath). should == 'Bar' end + it 'should return a string with contents of a xpath selector of a web page' do + Cinch::Toolbox.get_html_element('http://example.com/', "//div[@id='a1']", :xpath_full). + should == @fake_web_html + end + it 'should return nil if the css element does not exist' do Cinch::Toolbox.get_html_element('http://example.com/', '.foo2', :css). should be_nil end @@ -109,9 +117,19 @@ end describe 'time parseing' do it 'should parse seconds into a user friendly string' do Cinch::Toolbox.time_format(126). - should == '2m 6s' + should == '2 mins, 6 seconds' + end + + it 'should allow users to limit the kinds of units returned' do + Cinch::Toolbox.time_format(126020, [:days, :seconds]). + should == '1 days, 20 seconds' + end + + it 'should allow users to specify short form' do + Cinch::Toolbox.time_format(126000, [:days], :short). + should == '1d' end end end