Skip to content

Commit

Permalink
ruby 1.9 test improvements
Browse files Browse the repository at this point in the history
[Fixes spree#431]
  • Loading branch information
hybridindie authored and schof committed Jun 11, 2011
1 parent eddfde3 commit f3f1414
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -9,7 +9,7 @@ gem 'rake', '~> 0.8.7'
gemspec

group :test do
gem 'rspec-rails', '= 2.5.0'
gem 'rspec-rails', '= 2.6.1'
gem 'factory_girl_rails'
gem 'factory_girl', '= 1.3.3'
gem 'rcov'
Expand Down
2 changes: 1 addition & 1 deletion api/features/products.feature
Expand Up @@ -12,7 +12,7 @@ Feature: Products api description
And the response should be an array with 2 products

Scenario: Retrieve a list of products after searching
Given the following products exist:
Given the following product exist:
| name |
| apache baseball cap |
| zomg shirt |
Expand Down
45 changes: 23 additions & 22 deletions api/features/step_definitions/orders_steps.rb
Expand Up @@ -48,31 +48,31 @@
end

Then /^the response should be an array with (\d+) states/ do |num|
page = JSON.parse(last_response.body)
page.map { |d| d[name] }.length.should == num.to_i
page = JSON.load(last_response.body)
page.map { |d| d['name'] }.length.should == num.to_i
page.first.keys.sort.should == ["state"]

keys = ["abbr", "country_id", "id", "name"]
page.first['state'].keys.sort.should == keys
end

Then /^the response should have state information$/ do
page = JSON.parse(last_response.body)
page = JSON.load(last_response.body)
page['state']['abbr'].should be_true
page['state']['name'].should be_true
end

Then /^the response should be an array with (\d+) shipments/ do |num|
page = JSON.parse(last_response.body)
page.map { |d| d[name] }.length.should == num.to_i
page = JSON.load(last_response.body)
page.map { |d| d['name'] }.length.should == num.to_i
page.first.keys.sort.should == ["shipment"]

keys = ["address", "cost", "created_at", "id", "inventory_units", "number", "order_id", "shipped_at", "shipping_method", "state", "tracking", "updated_at"]
page.first['shipment'].keys.sort.should == keys
end

Then /^the response should have shipment information$/ do
page = JSON.parse(last_response.body)
page = JSON.load(last_response.body)
page['shipment']['address'].should be_true
page['shipment']['cost'].should be_true
page['shipment']['number'].should be_true
Expand All @@ -83,31 +83,32 @@


Then /^the response should be an array with (\d+) products?/ do |num|
page = JSON.parse(last_response.body)
page.map { |d| d[name] }.length.should == num.to_i
page = JSON.load(last_response.body)

page.map { |d| d['name'] }.length.should == num.to_i
page.first.keys.sort.should == ["product"]

keys = ["available_on", "count_on_hand", "created_at", "deleted_at", "description", "id", "meta_description", "meta_keywords", "name", "permalink", "shipping_category_id", "tax_category_id", "updated_at"]
page.first['product'].keys.sort.should == keys
end

Then /^the response should have product information$/ do
page = JSON.parse(last_response.body)
page = JSON.load(last_response.body)
page['product']['permalink'].should be_true
page['product']['name'].should be_true
page['product']['count_on_hand'].should be_true
end

Then /^the response should have product information for shirt$/ do
page = JSON.parse(last_response.body).first
page = JSON.load(last_response.body).first
page['product']['permalink'].should be_true
page['product']['name'].should == 'zomg shirt'
page['product']['count_on_hand'].should be_true
end

Then /^the response should be an array with (\d+) orders/ do |num|
page = JSON.parse(last_response.body)
page.map { |d| d[name] }.length.should == num.to_i
page = JSON.load(last_response.body)
page.map { |d| d['name'] }.length.should == num.to_i
page.first.keys.sort.should == ["order"]

keys = ["adjustment_total", "bill_address_id", "completed_at", "created_at", "credit_total", "email",
Expand All @@ -118,15 +119,15 @@
end

Then /^the response should have order information$/ do
page = JSON.parse(last_response.body)
page = JSON.load(last_response.body)
page['order']['number'].should be_true
page['order']['state'].should be_true
page['order']['email'].should be_true
page['order']['credit_total'].should be_true
end

Then /^the response should have country information$/ do
page = JSON.parse(last_response.body)
page = JSON.load(last_response.body)
page['country']['name'].should == 'Afghanistan'
page['country']['iso_name'].should == 'AFGHANISTAN'
page['country']['iso3'].should == 'AFG'
Expand All @@ -135,40 +136,40 @@
end

Then /^the response should be an array with (\d+) countries$/ do |num|
page = JSON.parse(last_response.body)
page.map { |d| d[name] }.length.should == num.to_i
page = JSON.load(last_response.body)
page.map { |d| d['name'] }.length.should == num.to_i
page.first.keys.sort.should == ["country"]

keys = ["id", "iso", "iso3", "iso_name", "name", "numcode"]
page.first['country'].keys.sort.should == keys
end

Then /^the response should be an array with (\d+) inventory units$/ do |num|
page = JSON.parse(last_response.body)
page.map { |d| d[name] }.length.should == num.to_i
page = JSON.load(last_response.body)
page.map { |d| d['name'] }.length.should == num.to_i
page.first.keys.sort.should == ["inventory_unit"]

keys = ["created_at", "id", "lock_version", "order_id", "return_authorization_id", "shipment_id", "state", "updated_at", "variant_id"]
page.first['inventory_unit'].keys.sort.should == keys
end

Then /^the response should have inventory unit information$/ do
page = JSON.parse(last_response.body)
page = JSON.load(last_response.body)
page['inventory_unit']['lock_version'].should be_true
page['inventory_unit']['state'].should be_true
end

Then /^the response should be an array with (\d+) line items$/ do |num|
page = JSON.parse(last_response.body)
page.map { |d| d[name] }.length.should == num.to_i
page = JSON.load(last_response.body)
page.map { |d| d['name'] }.length.should == num.to_i
page.first.keys.sort.should == ["line_item"]

keys = ["created_at", "description", "id", "order_id", "price", "quantity", "updated_at", "variant", "variant_id"]
page.first['line_item'].keys.sort.should == keys
end

Then /^the response should have line item information$/ do
page = JSON.parse(last_response.body)
page = JSON.load(last_response.body)
page['line_item']['description'].should match(/Size: S/)
page['line_item']['price'].should be_true
page['line_item']['quantity'].should be_true
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/Gemfile
Expand Up @@ -3,7 +3,7 @@ source 'http://rubygems.org'
gem 'rake', '~> 0.8.7'

group :test do
gem 'rspec-rails', '= 2.5.0'
gem 'rspec-rails', '= 2.6.1'
gem 'factory_girl', '= 1.3.3'
gem 'factory_girl_rails', '= 1.0.1'
gem 'rcov'
Expand Down

0 comments on commit f3f1414

Please sign in to comment.