spec/cinch-toolbox_spec.rb in cinch-toolbox-1.1.4 vs spec/cinch-toolbox_spec.rb in cinch-toolbox-1.1.6
- old
+ new
@@ -9,127 +9,125 @@
FakeWeb.register_uri( :get, "http://example.com/",
: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'
+ element = Cinch::Toolbox.get_html_element('http://example.com/', '.foo', :css)
+ expect(element).to eq('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
+ element = Cinch::Toolbox.get_html_element('http://example.com/', '.top', :css_full)
+ expect(element).to eq(@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'
+ element = Cinch::Toolbox.get_html_element('http://example.com/', "//div/div[1]", :xpath)
+ expect(element).to eq('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
+ element = Cinch::Toolbox.get_html_element('http://example.com/', "//div[@id='a1']", :xpath_full)
+ expect(element).to eq(@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
+ element = Cinch::Toolbox.get_html_element('http://example.com/', '.foo2', :css)
+ expect(element).to be_nil
end
it 'should return nil if the xpath element does not exist' do
- Cinch::Toolbox.get_html_element('http://example.com/', "//div/div[3]", :xpath).
- should be_nil
+ element = Cinch::Toolbox.get_html_element('http://example.com/', "//div/div[3]", :xpath)
+ expect(element).to be_nil
end
it 'should return nil if there is a problem finding the site' do
- Cinch::Toolbox.get_html_element('http://baddurl.com/', '.foo2', :css).
- should be_nil
+ element = Cinch::Toolbox.get_html_element('http://baddurl.com/', '.foo2', :css)
+ expect(element).to be_nil
end
it 'should return the page title if there is a http => https trasition' do
- Cinch::Toolbox.get_html_element('http://github.com/bhaberer/', 'title', :css).
- should include 'bhaberer (Brian Haberer)'
+ element = Cinch::Toolbox.get_html_element('http://github.com/bhaberer/', 'title', :css)
+ expect(element).to include('bhaberer (Brian Haberer)')
end
it 'should return nil if there is a https => http trasition' do
- Cinch::Toolbox.get_html_element('https://www.amazon.com/', 'title', :css).
- should be_nil
+ element = Cinch::Toolbox.get_html_element('https://www.amazon.com/', 'title', :css)
+ expect(element).to be_nil
end
end
describe 'the get_page_title method' do
- before(:all) do
- end
-
it 'should return a page title for a given url' do
- FakeWeb.register_uri( :get, "http://example.com/", :body => "<title>Page Title</table>")
- Cinch::Toolbox.get_page_title("http://example.com/").
- should == 'Page Title'
+ FakeWeb.register_uri( :get, 'http://example.com/',
+ body: '<body><title>Page Title</title></body>')
+ element = Cinch::Toolbox.get_page_title('http://example.com/')
+ expect(element).to eq('Page Title')
end
it 'should return Nil if a page is lacking a title' do
- FakeWeb.register_uri( :get, "http://example.com/", :body => "<body>Page Title</body>")
- Cinch::Toolbox.get_page_title("http://example.com/").
- should be_nil
+ FakeWeb.register_uri( :get, "http://example.com/", body: '<body>Page Title</body>')
+ element = Cinch::Toolbox.get_page_title('http://example.com/')
+ expect(element).to be_nil
end
it 'should return an image title if a page is a supported image type' do
[:jpg, :jpeg, :gif, :png].each do |image|
- Cinch::Toolbox.get_page_title("http://example.com/image.#{image}").
- should == "Image from http://example.com"
+ img = Cinch::Toolbox.get_page_title("http://example.com/image.#{image}")
+ expect(img).to eq('Image from http://example.com')
end
end
it 'should return Nil if a page is lacking a title' do
- Cinch::Toolbox.get_page_title("http://i.imgur.com/oMndYK7.jpg").
- should == "Anybody with a cat will relate. - Imgur"
+ element = Cinch::Toolbox.get_page_title("http://i.imgur.com/oMndYK7.jpg")
+ expect(element).to eq('Anybody with a cat will relate. - Imgur')
end
end
describe 'url shortening and expanding' do
it 'should shorten long urls' do
- Cinch::Toolbox.shorten('http://en.wikipedia.org/wiki/Llanfairpwllgwyngyllgogerychwyrndrobwllllan').
- should == "http://is.gd/PaUTII"
+ url = Cinch::Toolbox.shorten('http://en.wikipedia.org/wiki/Llanfairpwllgwyngyllgogerychwyrndrobwllllan')
+ expect(url).to eq('http://is.gd/PaUTII')
end
it 'should not shorten urls that are already short enough (< 45 cha)' do
- Cinch::Toolbox.shorten('http://en.wikipedia.org/').
- should == 'http://en.wikipedia.org/'
+ url = Cinch::Toolbox.shorten('http://en.wikipedia.org/')
+ expect(url).to eq('http://en.wikipedia.org/')
end
it 'should be able to expand shortened links' do
url = 'http://en.wikipedia.org/wiki/Llanfairpwllgwyngyll'
- Cinch::Toolbox.expand(Cinch::Toolbox.shorten(url)).should == url
+ expect(url).to eq(Cinch::Toolbox.expand(Cinch::Toolbox.shorten(url)))
end
end
describe 'truncate method' do
it 'should truncate text past the limit' do
foo = String.new
1000.times { foo << 'a' }
- Cinch::Toolbox.truncate(foo).length.should == 250
+ expect(Cinch::Toolbox.truncate(foo).length).to eq(250)
end
it 'should not truncate text within limit' do
foo = String.new
1000.times { foo << 'a' }
- Cinch::Toolbox.truncate(foo, 100).length.should == 100
+ expect(Cinch::Toolbox.truncate(foo, 100).length).to eq(100)
end
end
describe 'time parseing' do
it 'should parse seconds into a user friendly string' do
- Cinch::Toolbox.time_format(126).
- should == '2 mins, 6 seconds'
+ expect(Cinch::Toolbox.time_format(126))
+ .to eq('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'
+ expect(Cinch::Toolbox.time_format(126020, [:days, :seconds]))
+ .to eq('1 days, 20 seconds')
end
it 'should allow users to specify short form' do
- Cinch::Toolbox.time_format(126000, [:days], :short).
- should == '1d'
+ expect(Cinch::Toolbox.time_format(126000, [:days], :short))
+ .to eq('1d')
end
end
end