Skip to content

Commit

Permalink
Refactor duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorothee committed Jan 8, 2016
1 parent 48e5c88 commit 54ef219
Showing 1 changed file with 77 additions and 141 deletions.
218 changes: 77 additions & 141 deletions spec/shipcloud/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,150 +95,86 @@

Shipcloud::Shipment.all

expect(Shipcloud::Shipment).to have_received(:new).
with(
"id" => "86afb143f9c9c0cfd4eb7a7c26a5c616585a6271",
"carrier_tracking_no" => "43128000105",
"carrier" => "hermes",
"service" => "standard",
"created_at" => "2014-11-12T14:03:45+01:00",
"price" => 3.5,
"tracking_url" => "http://track.shipcloud.dev/de/86afb143f9",
"to" => {
"first_name" => "Hans",
"last_name" => "Meier",
"street" => "Semmelweg",
"street_no" => "1",
"zip_code" => "12345",
"city" => "Hamburg",
"country" => "DE"
},
"from" => {
"company" => "shipcloud GmbH",
"first_name" => "Max",
"last_name" => "Mustermann",
"street" => "Musterallee",
"street_no" => "43",
"city" => "Berlin",
"zip_code" => "10000"
},
"packages" => {
"id" => "be81573799958587ae891b983aabf9c4089fc462",
"length" => 10.0,
"width" => 10.0,
"height" => 10.0,
"weight" => 1.5
}
)

expect(Shipcloud::Shipment).to have_received(:new).
with(
"id" => "be81573799958587ae891b983aabf9c4089fc462",
"carrier_tracking_no" => "1Z12345E1305277940",
"carrier" => "ups",
"service" => "standard",
"created_at" => "2014-11-12T14:03:45+01:00",
"price" => 3.0,
"tracking_url" => "http://track.shipcloud.dev/de/be598a2fd2",
"to" => {
"first_name" => "Test",
"last_name" => "Kunde",
"street" => "Gluckstr.",
"street_no" => "57",
"zip_code" => "22081",
"city" => "Hamburg",
"country" => "DE"
},
"from" => {
"company" => "shipcloud GmbH",
"first_name" => "Max",
"last_name" => "Mustermann",
"street" => "Musterallee",
"street_no" => "43",
"city" => "Berlin",
"zip_code" => "10000"
},
"packages" => {
"id" => "74d4f1fc193d8a7ca542d1ee4e2021f3ddb82242",
"length" => 15.0,
"width" => 20.0,
"height" => 10.0,
"weight" => 2.0
}
)
expect(Shipcloud::Shipment).to have_received(:new).with(hermes_shipment)
expect(Shipcloud::Shipment).to have_received(:new).with(ups_shipment)
end
end

def stub_shipments_request
allow(Shipcloud).to receive(:request).with(:get, "shipments", {}).and_return(
[
{ "id" => "86afb143f9c9c0cfd4eb7a7c26a5c616585a6271",
"carrier_tracking_no" => "43128000105",
"carrier" => "hermes",
"service" => "standard",
"created_at" => "2014-11-12T14:03:45+01:00",
"price" => 3.5,
"tracking_url" => "http://track.shipcloud.dev/de/86afb143f9",
"to" => {
"first_name" => "Hans",
"last_name" => "Meier",
"street" => "Semmelweg",
"street_no" => "1",
"zip_code" => "12345",
"city" => "Hamburg",
"country" => "DE"
},
"from" => {
"company" => "shipcloud GmbH",
"first_name" => "Max",
"last_name" => "Mustermann",
"street" => "Musterallee",
"street_no" => "43",
"city" => "Berlin",
"zip_code" => "10000"
},
"packages" => {
"id" => "be81573799958587ae891b983aabf9c4089fc462",
"length" => 10.0,
"width" => 10.0,
"height" => 10.0,
"weight" => 1.5
}
},
{ "id" => "be81573799958587ae891b983aabf9c4089fc462",
"carrier_tracking_no" => "1Z12345E1305277940",
"carrier" => "ups",
"service" => "standard",
"created_at" => "2014-11-12T14:03:45+01:00",
"price" => 3.0,
"tracking_url" => "http://track.shipcloud.dev/de/be598a2fd2",
"to" => {
"first_name" => "Test",
"last_name" => "Kunde",
"street" => "Gluckstr.",
"street_no" => "57",
"zip_code" => "22081",
"city" => "Hamburg",
"country" => "DE"
},
"from" => {
"company" => "shipcloud GmbH",
"first_name" => "Max",
"last_name" => "Mustermann",
"street" => "Musterallee",
"street_no" => "43",
"city" => "Berlin",
"zip_code" => "10000"
},
"packages" => {
"id" => "74d4f1fc193d8a7ca542d1ee4e2021f3ddb82242",
"length" => 15.0,
"width" => 20.0,
"height" => 10.0,
"weight" => 2.0
}
}
]
)
allow(Shipcloud).to receive(:request).
with(:get, "shipments", {}).
and_return([hermes_shipment, ups_shipment])
end

def hermes_shipment
{ "id" => "86afb143f9c9c0cfd4eb7a7c26a5c616585a6271",
"carrier_tracking_no" => "43128000105",
"carrier" => "hermes",
"service" => "standard",
"created_at" => "2014-11-12T14:03:45+01:00",
"price" => 3.5,
"tracking_url" => "http://track.shipcloud.dev/de/86afb143f9",
"to" => {
"first_name" => "Hans",
"last_name" => "Meier",
"street" => "Semmelweg",
"street_no" => "1",
"zip_code" => "12345",
"city" => "Hamburg",
"country" => "DE"
},
"from" => {
"company" => "shipcloud GmbH",
"first_name" => "Max",
"last_name" => "Mustermann",
"street" => "Musterallee",
"street_no" => "43",
"city" => "Berlin",
"zip_code" => "10000"
},
"packages" => {
"id" => "be81573799958587ae891b983aabf9c4089fc462",
"length" => 10.0,
"width" => 10.0,
"height" => 10.0,
"weight" => 1.5
}
}
end

def ups_shipment
{ "id" => "be81573799958587ae891b983aabf9c4089fc462",
"carrier_tracking_no" => "1Z12345E1305277940",
"carrier" => "ups",
"service" => "standard",
"created_at" => "2014-11-12T14:03:45+01:00",
"price" => 3.0,
"tracking_url" => "http://track.shipcloud.dev/de/be598a2fd2",
"to" => {
"first_name" => "Test",
"last_name" => "Kunde",
"street" => "Gluckstr.",
"street_no" => "57",
"zip_code" => "22081",
"city" => "Hamburg",
"country" => "DE"
},
"from" => {
"company" => "shipcloud GmbH",
"first_name" => "Max",
"last_name" => "Mustermann",
"street" => "Musterallee",
"street_no" => "43",
"city" => "Berlin",
"zip_code" => "10000"
},
"packages" => {
"id" => "74d4f1fc193d8a7ca542d1ee4e2021f3ddb82242",
"length" => 15.0,
"width" => 20.0,
"height" => 10.0,
"weight" => 2.0
}
}
end
end

0 comments on commit 54ef219

Please sign in to comment.