spec/photograph/artist_spec.rb in photograph-0.0.2 vs spec/photograph/artist_spec.rb in photograph-0.0.4

- old
+ new

@@ -1,49 +1,83 @@ require 'spec_helper' module Photograph describe Artist do - URL = "http://rubygems.org" + let(:url) { 'http://rubygems.org' } + subject { Artist.new :url => url } - it "should instanciate a new artist" do - Artist.new :url => URL - end + describe '.new' do + it { expect(subject).to be_kind_of(Artist) } - it "should accept a block when shooting" do - Artist.new(:url => URL).shoot! do |image| - image.should respond_to(:path) + it('raises an error when not given a url') do + expect{ Artist.new }.to raise_error(Artist::MissingUrlError) end + + it('should leave http version of url untouched as it is already valid') do + expect(subject.options[:url]).to eq(url) + end + + it('should leave https version of url untouched as it is already valid') do + expect(Artist.new(:url => 'https://rubygems.org').options[:url]).to eq('https://rubygems.org') + end + + it('should prepend http:// to the url if protocol is not present') do + expect(Artist.new(:url => 'github.com').options[:url]).to eq('http://github.com') + end end - it "should raise an error without an url" do - expect { Artist.new }.to raise_error(Artist::MissingUrlError) + describe '#options' do + it('should have default value for x') { expect(subject.options[:x]).to eq(0) } + it('should have default value for y') { expect(subject.options[:y]).to eq(0) } + it('should have default value for w') { expect(subject.options[:w]).to eq(1280) } + it('should have default value for h') { expect(subject.options[:h]).to eq(1024) } end - describe "Default size values" do - before(:each) { @artist = Artist.new :url => URL } + describe '#shoot!' do + context 'when browser has been provided' do + let(:browser) { Capybara::Session.new(:poltergeist) } + subject { Artist.new(:url => url, :browser => browser) } - it "should have default values for x,y : 0,0" do - @artist.options[:x].should == 0 - @artist.options[:y].should == 0 + it 're-uses the browser provided to Artist#new' do + browser.should_receive(:visit) + subject.shoot! {} + end end - it"should have default values for h,w : 1280, 1024" do - @artist.options[:w].should == 1280 - @artist.options[:h].should == 1024 + it('should accept a block when shooting') do + subject.shoot!{|image| image.should respond_to(:path) } end - end - describe "Cropping" do - before(:each) { @artist = Artist.new :url => URL } + it('should raise an exception if no block was given when shooting') do + expect{ subject.shoot! }.to raise_error(Artist::DeprecationError) + end - it "should take a screenshot large enough to crop later" do - pending + describe 'Cropping' do + subject { Artist.new :url => url, :x => 200, :y => 100, :h => 400, :w => 400 } + before { subject.browser.driver.stub(:render) } - @artist = Artist.new :url => URL, :x => 200, :y => 100, :h => 400, :w => 400 + xit 'should take a screenshot large enough to crop later' do + subject.shoot! + end + end + end - Artist.browser.driver.stub :render + describe "#before" do + subject { Artist.new :url => url } + before do + subject.browser.driver.stub(:visit) + subject.browser.driver.stub(:click_link) + subject.browser.driver.stub(:render) + subject.stub(:adjust_image) + end - @artist.shoot! + it('should call the before hook before shooting') do + subject.before do |browser| + browser.click_link "Use the API" + end + + allow(subject.browser).to receive(:click_link) + subject.shoot! {} end end end end