spec/examples/post_spec.rb in tumblr_client-0.8.4 vs spec/examples/post_spec.rb in tumblr_client-0.8.5
- old
+ new
@@ -12,11 +12,11 @@
describe :delete do
context 'when deleting a post' do
before do
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/delete", {
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post/delete", {
:id => post_id
})
end
it 'should setup a delete properly' do
@@ -31,73 +31,73 @@
[:photo, :audio, :video].each do |type|
describe type do
context 'when passing data as an array of filepaths' do
before do
fakefile = OpenStruct.new :read => file_data
- File.stub(:open).with(file_path + '.jpg').and_return(fakefile)
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
+ allow(File).to receive(:open).with(file_path + '.jpg').and_return(fakefile)
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
'data[0]' => kind_of(Faraday::UploadIO),
:id => 123,
:type => type
}).and_return('response')
end
it 'should be able to pass data as an array of filepaths' do
r = client.edit blog_name, :data => [file_path + ".jpg"], :id => 123, :type => type
- r.should == 'response'
+ expect(r).to eq('response')
end
it 'should be able to pass data as an array of uploadios' do
r = client.edit blog_name, :data => [Faraday::UploadIO.new(StringIO.new, 'image/jpeg')], :id => 123, :type => type
- r.should == 'response'
+ expect(r).to eq('response')
end
end
context 'when passing data different ways' do
before do
fakefile = OpenStruct.new :read => file_data
- File.stub(:open).with(file_path + '.jpg').and_return(fakefile)
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
+ allow(File).to receive(:open).with(file_path + '.jpg').and_return(fakefile)
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
'data' => kind_of(Faraday::UploadIO),
:id => 123,
:type => type
}).and_return('response')
end
it 'should be able to pass data as a single filepath' do
r = client.edit blog_name, :data => file_path + ".jpg", :id => 123, :type => type
- r.should == 'response'
+ expect(r).to eq('response')
end
it 'should be able to pass data as a single uploadio' do
r = client.edit blog_name, :data => Faraday::UploadIO.new(StringIO.new, 'image/jpeg'), :id => 123, :type => type
- r.should == 'response'
+ expect(r).to eq('response')
end
end
end
end
it 'should make the correct call' do
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
:id => 123
}).and_return('response')
r = client.edit blog_name, :id => 123
- r.should == 'response'
+ expect(r).to eq('response')
end
end
describe :reblog do
it 'should make the correct call' do
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/reblog", {
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post/reblog", {
:id => 123
}).and_return('response')
r = client.reblog blog_name, :id => 123
- r.should == 'response'
+ expect(r).to eq('response')
end
end
# Simple post types
@@ -108,30 +108,30 @@
describe type do
context 'when passing an option which is not allowed' do
it 'should raise an error' do
- lambda {
+ expect(lambda {
client.send type, blog_name, :not => 'an option'
- }.should raise_error ArgumentError
+ }).to raise_error ArgumentError
end
end
context 'when passing valid data' do
before do
@val = 'hello world'
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post", {
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post", {
field.to_sym => @val,
:type => type.to_s
}).and_return('response')
end
it 'should set up the call properly' do
r = client.send type, blog_name, field.to_sym => @val
- r.should == 'response'
+ expect(r).to eq('response')
end
end
end
@@ -144,25 +144,25 @@
let(:args) { { :source => 'somesource' } }
context 'with a valid post type' do
before do
- client.should_receive(:photo).with(blog_name, args).and_return 'hi'
+ expect(client).to receive(:photo).with(blog_name, args).and_return 'hi'
end
it 'should call the right method and grab the return' do
- client.create_post(:photo, blog_name, args).should == 'hi'
+ expect(client.create_post(:photo, blog_name, args)).to eq('hi')
end
end
context 'with an invalid post type' do
it 'should raise an error' do
- lambda do
+ expect(lambda do
client.create_post(:fake, blog_name, args)
- end.should raise_error ArgumentError, '"fake" is not a valid post type'
+ end).to raise_error ArgumentError, '"fake" is not a valid post type'
end
end
end
@@ -173,86 +173,86 @@
describe type do
context 'when passing an option which is not allowed' do
it 'should raise an error' do
- lambda {
+ expect(lambda {
client.send type, blog_name, :not => 'an option'
- }.should raise_error ArgumentError
+ }).to raise_error ArgumentError
end
end
context 'when passing data as an array of filepaths' do
before do
fakefile = OpenStruct.new :read => file_data
- File.stub(:open).with(file_path + '.jpg').and_return(fakefile)
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post", {
+ allow(File).to receive(:open).with(file_path + '.jpg').and_return(fakefile)
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post", {
'data[0]' => kind_of(Faraday::UploadIO),
:type => type.to_s
}).and_return('post')
end
it 'should be able to pass data as an array of filepaths' do
r = client.send type, blog_name, :data => [file_path + ".jpg"]
- r.should == 'post'
+ expect(r).to eq('post')
end
it 'should be able to pass data as an array of uploadios' do
r = client.send type, blog_name, :data => [Faraday::UploadIO.new(StringIO.new, 'image/jpeg')]
- r.should == 'post'
+ expect(r).to eq('post')
end
end
context 'when passing data different ways' do
before do
fakefile = OpenStruct.new :read => file_data
- File.stub(:open).with(file_path + '.jpg').and_return(fakefile)
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post", {
+ allow(File).to receive(:open).with(file_path + '.jpg').and_return(fakefile)
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post", {
'data' => kind_of(Faraday::UploadIO),
:type => type.to_s
}).and_return('post')
end
it 'should be able to pass data as a single filepath' do
r = client.send type, blog_name, :data => file_path + ".jpg"
- r.should == 'post'
+ expect(r).to eq('post')
end
it 'should be able to pass data as a single uploadio' do
r = client.send type, blog_name, :data => Faraday::UploadIO.new(StringIO.new, 'image/jpeg')
- r.should == 'post'
+ expect(r).to eq('post')
end
end
# Only photos have source
if type == :photo
context 'when passing source different ways' do
it 'should be able to be passed as a string' do
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post", {
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post", {
:source => source,
:type => type.to_s
})
client.send type, blog_name, :source => source
end
it 'should be able to be passed as an array' do
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post", {
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post", {
'source[0]' => source,
'source[1]' => source,
:type => type.to_s
})
client.send type, blog_name, :source => [source, source]
end
it 'should be able to be passed as an array on edit' do
- client.should_receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
+ expect(client).to receive(:post).once.with("v2/blog/#{blog_name}/post/edit", {
:id => post_id,
'source[0]' => source,
'source[1]' => source
})
client.edit blog_name, :id => post_id, :source => [source, source]
@@ -263,12 +263,12 @@
end
context 'when passing colliding options' do
it 'should get an error when passing data & source' do
- lambda {
+ expect(lambda {
client.send type, blog_name, :data => 'hi', :source => 'bye'
- }.should raise_error ArgumentError
+ }).to raise_error ArgumentError
end
end
end