Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Commit

Permalink
Switch all specs to new 'expect' syntax instead of 'should'.
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-buente committed Aug 7, 2014
1 parent 8bd1c3f commit 5a01e85
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 184 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ rosemary CHANGELOG
===================================
This file is used to list changes made in each version.

v0.4.2 (2014 Aug 7)
------

* Allow arbitrary tags to be attached to changeset
* Upgrade all specs to 'expect' syntax instead of 'should'


v0.4.1 (2014 May 27)
------
Expand Down
42 changes: 21 additions & 21 deletions spec/integration/changeset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ def stubbed_request
stubbed_request.to_return(:status => 200, :body => single_changeset, :headers => {'Content-Type' => 'application/xml'})
changeset = osm.find_changeset(10)
assert_requested :get, request_url, :times => 1
changeset.class.should eql Changeset
expect(changeset.class).to eql Changeset
end

it "should raise an NotFound error, when a changeset cannot be found" do
stubbed_request.to_return(:status => 404, :body => '', :headers => {'Content-Type' => 'text/plain'})
node = osm.find_changeset(10)
node.should be_nil
expect(node).to be_nil
end
end

Expand All @@ -102,34 +102,34 @@ def stub_create_request
body = Changeset.new(:tags => { :comment => 'New changeset' }).to_xml

stub_create_request.with(:body => body).to_return(:status => 200, :body => "3", :headers => {'Content-Type' => 'plain/text'})
auth_osm.should_receive(:find_changeset).with(3).and_return(cs = double())
auth_osm.create_changeset('New changeset').should == cs
expect(auth_osm).to receive(:find_changeset).with(3).and_return(cs = double())
expect(auth_osm.create_changeset('New changeset')).to eql cs
end
end

describe "#find_or_create_open_changeset" do
it "returns an exisiting changeset if that exists and is open" do
auth_osm.should_receive(:find_changeset).with(3).and_return(cs = double(:open? => true))
auth_osm.should_not_receive(:create_changeset)
auth_osm.find_or_create_open_changeset(3, "some foo comment").should == cs
expect(auth_osm).to receive(:find_changeset).with(3).and_return(cs = double(:open? => true))
expect(auth_osm).not_to receive(:create_changeset)
expect(auth_osm.find_or_create_open_changeset(3, "some foo comment")).to eql cs
end

it "returns an new changeset if the requested one exists and is closed" do
auth_osm.should_receive(:find_changeset).with(3).and_return(double(:open? => false))
auth_osm.should_receive(:create_changeset).with("some foo comment", {}).and_return(cs = double())
auth_osm.find_or_create_open_changeset(3, "some foo comment").should == cs
expect(auth_osm).to receive(:find_changeset).with(3).and_return(double(:open? => false))
expect(auth_osm).to receive(:create_changeset).with("some foo comment", {}).and_return(cs = double())
expect(auth_osm.find_or_create_open_changeset(3, "some foo comment")).to eql cs
end

it "returns an new changeset if the requested one doesn't exist" do
auth_osm.should_receive(:find_changeset).with(3).and_return(nil)
auth_osm.should_receive(:create_changeset).with("some foo comment", {}).and_return(cs = double())
auth_osm.find_or_create_open_changeset(3, "some foo comment").should == cs
expect(auth_osm).to receive(:find_changeset).with(3).and_return(nil)
expect(auth_osm).to receive(:create_changeset).with("some foo comment", {}).and_return(cs = double())
expect(auth_osm.find_or_create_open_changeset(3, "some foo comment")).to eql cs
end

it "appends arbitrary tags to the changeset itself" do
auth_osm.should_receive(:find_changeset).with(3).and_return(nil)
auth_osm.should_receive(:create_changeset).with("some foo comment", :source => 'http://example.com' ).and_return(cs = double())
auth_osm.find_or_create_open_changeset(3, "some foo comment", :source => 'http://example.com' ).should == cs
expect(auth_osm).to receive(:find_changeset).with(3).and_return(nil)
expect(auth_osm).to receive(:create_changeset).with("some foo comment", :source => 'http://example.com' ).and_return(cs = double())
expect(auth_osm.find_or_create_open_changeset(3, "some foo comment", :source => 'http://example.com' )).to eql cs
end
end

Expand All @@ -150,21 +150,21 @@ def stubbed_request
it "should not find changeset for user if user has none" do
stubbed_request.to_return(:status => 200, :body => missing_changeset, :headers => {'Content-Type' => 'application/xml'})
changesets = auth_osm.find_changesets_for_user
changesets.should be_empty
expect(changesets).to be_empty
end

it "should find a single changeset for user" do
stubbed_request.to_return(:status => 200, :body => single_changeset, :headers => {'Content-Type' => 'application/xml'})
changesets = auth_osm.find_changesets_for_user
changesets.size.should eql 1
changesets.first.class.should eql Changeset
expect(changesets.size).to eql 1
expect(changesets.first.class).to eql Changeset
end

it "should find a multiple changesets for a user" do
stubbed_request.to_return(:status => 200, :body => multiple_changeset, :headers => {'Content-Type' => 'application/xml'})
changesets = auth_osm.find_changesets_for_user
changesets.size.should eql 2
changesets.first.class.should eql Changeset
expect(changesets.size).to eql 2
expect(changesets.first.class).to eql Changeset
end
end

Expand Down
108 changes: 54 additions & 54 deletions spec/integration/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,32 +72,32 @@ def stubbed_request
stubbed_request.to_return(:status => 200, :body => valid_fake_node, :headers => {'Content-Type' => 'application/xml'})
node = osm.find_node 1234
assert_requested :get, request_url, :times => 1
node.class.should eql Node
node.tags.size.should eql 3
node.tags['name'].should eql 'The rose'
node['name'].should eql 'The rose'
expect(node.class).to eql Node
expect(node.tags.size).to eql 3
expect(node.tags['name']).to eql 'The rose'
expect(node['name']).to eql 'The rose'
node.add_tags('wheelchair' => 'yes')
node['wheelchair'].should eql 'yes'
expect(node['wheelchair']).to eql 'yes'
end

it "should raise a Unavailable, when api times out" do
stubbed_request.to_timeout
lambda {
expect {
node = osm.find_node(1234)
}.should raise_error(Unavailable)
}.to raise_exception(Unavailable)
end

it "should raise an Gone error, when a node has been deleted" do
stubbed_request.to_return(:status => 410, :body => '', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
node = osm.find_node(1234)
}.should raise_error(Gone)
}.to raise_exception(Gone)
end

it "should raise an NotFound error, when a node cannot be found" do
stubbed_request.to_return(:status => 404, :body => '', :headers => {'Content-Type' => 'text/plain'})
node = osm.find_node(1234)
node.should be_nil
expect(node).to be_nil
end
end

Expand Down Expand Up @@ -142,37 +142,37 @@ def stubbed_request

it "should raise a Unavailable, when api times out" do
stubbed_request.to_timeout
lambda {
expect {
new_id = osm.create(node, changeset)
}.should raise_error(Unavailable)
}.to raise_exception(Unavailable)
end

it "should not create a Node with invalid xml but raise BadRequest" do
stubbed_request.to_return(:status => 400, :body => 'The given node is invalid', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
new_id = osm.save(node, changeset)
}.should raise_error(BadRequest)
}.to raise_exception(BadRequest)
end

it "should not allow to create a node when a changeset has been closed" do
stubbed_request.to_return(:status => 409, :body => 'The given node is invalid', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
new_id = osm.save(node, changeset)
}.should raise_error(Conflict)
}.to raise_exception(Conflict)
end

it "should not allow to create a node when no authentication client is given" do
osm = Api.new
lambda {
expect {
osm.save(node, changeset)
}.should raise_error(CredentialsMissing)
}.to raise_exception(CredentialsMissing)
end

it "should set a changeset" do
stubbed_request.to_return(:status => 200, :body => '123', :headers => {'Content-Type' => 'text/plain'})
node.changeset = nil
osm.save(node, changeset)
node.changeset.should == changeset.id
expect(node.changeset).to eql changeset.id
end
end

Expand All @@ -191,16 +191,16 @@ def stubbed_request
stub_request(:put, "http://a_username:a_password@www.openstreetmap.org/api/0.6/node/123").to_return(:status => 200, :body => '43', :headers => {'Content-Type' => 'text/plain'})
node.tags['amenity'] = 'restaurant'
node.tags['name'] = 'Il Tramonto'
node.should_receive(:changeset=)
expect(node).to receive(:changeset=)
new_version = osm.save(node, changeset)
new_version.should eql 43
expect(new_version).to eql 43
end

it "should set a changeset" do
stub_request(:put, "http://a_username:a_password@www.openstreetmap.org/api/0.6/node/123").to_return(:status => 200, :body => '43', :headers => {'Content-Type' => 'text/plain'})
node.changeset = nil
osm.save(node, changeset)
node.changeset.should == changeset.id
expect(node.changeset).to eql changeset.id
end


Expand All @@ -225,56 +225,56 @@ def stubbed_request

it "should delete an existing node" do
stub_request(:delete, "http://a_username:a_password@www.openstreetmap.org/api/0.6/node/123").to_return(:status => 200, :body => '43', :headers => {'Content-Type' => 'text/plain'})
node.should_receive(:changeset=)
expect(node).to receive(:changeset=)
new_version = osm.destroy(node, changeset)
new_version.should eql 43 # new version number
expect(new_version).to eql 43 # new version number
end

it "should raise an error if node to be deleted is still part of a way" do
stub_request(:delete, "http://a_username:a_password@www.openstreetmap.org/api/0.6/node/123").to_return(:status => 400, :body => 'Version does not match current database version', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
response = osm.destroy(node, changeset)
response.should eql "Version does not match current database version"
}.should raise_error BadRequest
expect(response).to eql "Version does not match current database version"
}.to raise_exception BadRequest
end

it "should raise an error if node cannot be found" do
stub_request(:delete, "http://a_username:a_password@www.openstreetmap.org/api/0.6/node/123").to_return(:status => 404, :body => 'Node cannot be found', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
response = osm.destroy(node, changeset)
response.should eql "Node cannot be found"
}.should raise_error NotFound
expect(response).to eql "Node cannot be found"
}.to raise_exception NotFound
end

it "should raise an error if there is a conflict" do
stub_request(:delete, "http://a_username:a_password@www.openstreetmap.org/api/0.6/node/123").to_return(:status => 409, :body => 'Node has been deleted in this changeset', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
response = osm.destroy(node, changeset)
response.should eql "Node has been deleted in this changeset"
}.should raise_error Conflict
expect(response).to eql "Node has been deleted in this changeset"
}.to raise_exception Conflict
end

it "should raise an error if the node is already delted" do
stub_request(:delete, "http://a_username:a_password@www.openstreetmap.org/api/0.6/node/123").to_return(:status => 410, :body => 'Node has been deleted', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
response = osm.destroy(node, changeset)
response.should eql "Node has been deleted"
}.should raise_error Gone
expect(response).to eql "Node has been deleted"
}.to raise_exception Gone
end

it "should raise an error if the node is part of a way" do
stub_request(:delete, "http://a_username:a_password@www.openstreetmap.org/api/0.6/node/123").to_return(:status => 412, :body => 'Node 123 is still used by way 456', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
response = osm.destroy(node, changeset)
response.should eql "Node 123 is still used by way 456"
}.should raise_error Precondition
expect(response).to eql "Node 123 is still used by way 456"
}.to raise_exception Precondition
end

it "should set the changeset an existing node" do
stub_request(:delete, "http://a_username:a_password@www.openstreetmap.org/api/0.6/node/123").to_return(:status => 200, :body => '43', :headers => {'Content-Type' => 'text/plain'})
node.changeset = nil
new_version = osm.destroy(node, changeset)
node.changeset.should == changeset.id
expect(node.changeset).to eql changeset.id
end
end
end
Expand Down Expand Up @@ -324,37 +324,37 @@ def stubbed_request

it "should create a new Node from given attributes" do
stubbed_request.to_return(:status => 200, :body => '123', :headers => {'Content-Type' => 'text/plain'})
node.id.should be_nil
expect(node.id).to be_nil
new_id = osm.save(node, changeset)
end

it "should raise a Unavailable, when api times out" do
stubbed_request.to_timeout
lambda {
expect {
new_id = osm.save(node, changeset)
}.should raise_error(Unavailable)
}.to raise_exception(Unavailable)
end


it "should not create a Node with invalid xml but raise BadRequest" do
stubbed_request.to_return(:status => 400, :body => 'The given node is invalid', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
new_id = osm.save(node, changeset)
}.should raise_error(BadRequest)
}.to raise_exception(BadRequest)
end

it "should not allow to create a node when a changeset has been closed" do
stubbed_request.to_return(:status => 409, :body => 'The given node is invalid', :headers => {'Content-Type' => 'text/plain'})
lambda {
expect {
new_id = osm.save(node, changeset)
}.should raise_error(Conflict)
}.to raise_exception(Conflict)
end

it "should not allow to create a node when no authentication client is given" do
osm = Api.new
lambda {
expect {
osm.save(node, changeset)
}.should raise_error(CredentialsMissing)
}.to raise_exception(CredentialsMissing)
end

end
Expand All @@ -375,9 +375,9 @@ def stubbed_request
stub_request(:put, "http://www.openstreetmap.org/api/0.6/node/123").to_return(:status => 200, :body => '43', :headers => {'Content-Type' => 'text/plain'})
node.tags['amenity'] = 'restaurant'
node.tags['name'] = 'Il Tramonto'
node.should_receive(:changeset=)
expect(node).to receive(:changeset=)
new_version = osm.save(node, changeset)
new_version.should eql 43
expect(new_version).to eql 43
end
end

Expand All @@ -395,11 +395,11 @@ def stubbed_request

it "should delete an existing node" do
stub_request(:delete, "http://www.openstreetmap.org/api/0.6/node/123").to_return(:status => 200, :body => '43', :headers => {'Content-Type' => 'text/plain'})
node.should_receive(:changeset=)
lambda {
expect(node).to receive(:changeset=)
expect {
# Delete is not implemented using oauth
new_version = osm.destroy(node, changeset)
}.should raise_error(NotImplemented)
}.to raise_exception(NotImplemented)
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/integration/note_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ def valid_note
to_return(:status => 200, :body => valid_fake_note, :headers => {'Content-Type' => 'application/xml'})

new_note = osm.create_note(valid_note)
new_note.id.should eql '174576'
new_note.lon.should eql '102.2205'
new_note.lat.should eql '2.1059'
new_note.text.should eql 'Test note'
new_note.user.should eql 'osmthis'
new_note.action.should eql 'opened'
expect(new_note.id).to eql '174576'
expect(new_note.lon).to eql '102.2205'
expect(new_note.lat).to eql '2.1059'
expect(new_note.text).to eql 'Test note'
expect(new_note.user).to eql 'osmthis'
expect(new_note.action).to eql 'opened'
end
end

Expand Down
Loading

0 comments on commit 5a01e85

Please sign in to comment.