Skip to content

Commit 66591f5

Browse files
committed
Merge pull request #576 from wing328/ruby_petstore_test
Fix Ruby rspec
2 parents 3096c6c + cb2f1e1 commit 66591f5

File tree

14 files changed

+89
-360
lines changed

14 files changed

+89
-360
lines changed

modules/swagger-codegen/src/main/resources/ruby/swagger/configuration.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ module Swagger
99
def initialize
1010
@format = 'json'
1111
@scheme = 'http'
12-
@host = 'api.wordnik.com'
13-
@base_path = '/v4'
12+
@host = 'petstore.swagger.io'
13+
@base_path = '/v2'
1414
@user_agent = "ruby-swagger-#{Swagger::VERSION}"
15-
@inject_format = true
15+
@inject_format = false
1616
@force_ending_format = false
1717
@camelize_params = true
1818
end

modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ module Swagger
157157
end
158158

159159
def make
160-
logger = Logger.new STDOUT
161-
logger.debug self.url
160+
#TODO use configuration setting to determine if debugging
161+
#logger = Logger.new STDOUT
162+
#logger.debug self.url
162163
response = case self.http_method.to_sym
163164
when :get,:GET
164165
Typhoeus::Request.get(

samples/client/petstore/ruby/Gemfile.lock

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,43 @@ PATH
99
GEM
1010
remote: http://rubygems.org/
1111
specs:
12-
ZenTest (4.7.0)
13-
addressable (2.2.8)
12+
ZenTest (4.11.0)
13+
addressable (2.3.8)
1414
autotest (4.4.6)
1515
ZenTest (>= 4.4.1)
16-
autotest-fsevent (0.2.8)
16+
autotest-fsevent (0.2.10)
1717
sys-uname
1818
autotest-growl (0.2.16)
1919
autotest-rails-pure (4.1.2)
20-
crack (0.3.1)
21-
diff-lcs (1.1.3)
22-
ffi (1.0.11)
23-
json (1.7.0)
24-
mime-types (1.18)
25-
rspec (2.9.0)
26-
rspec-core (~> 2.9.0)
27-
rspec-expectations (~> 2.9.0)
28-
rspec-mocks (~> 2.9.0)
29-
rspec-core (2.9.0)
30-
rspec-expectations (2.9.1)
31-
diff-lcs (~> 1.1.3)
32-
rspec-mocks (2.9.0)
33-
sys-uname (0.9.0)
20+
crack (0.4.2)
21+
safe_yaml (~> 1.0.0)
22+
diff-lcs (1.2.5)
23+
ethon (0.7.3)
24+
ffi (>= 1.3.0)
25+
ffi (1.9.8)
26+
json (1.8.2)
27+
rspec (3.2.0)
28+
rspec-core (~> 3.2.0)
29+
rspec-expectations (~> 3.2.0)
30+
rspec-mocks (~> 3.2.0)
31+
rspec-core (3.2.2)
32+
rspec-support (~> 3.2.0)
33+
rspec-expectations (3.2.0)
34+
diff-lcs (>= 1.2.0, < 2.0)
35+
rspec-support (~> 3.2.0)
36+
rspec-mocks (3.2.1)
37+
diff-lcs (>= 1.2.0, < 2.0)
38+
rspec-support (~> 3.2.0)
39+
rspec-support (3.2.2)
40+
safe_yaml (1.0.4)
41+
sys-uname (0.9.2)
3442
ffi (>= 1.0.0)
35-
typhoeus (0.3.3)
36-
mime-types
37-
vcr (2.1.1)
38-
webmock (1.8.6)
39-
addressable (>= 2.2.7)
40-
crack (>= 0.1.7)
43+
typhoeus (0.7.1)
44+
ethon (>= 0.7.1)
45+
vcr (2.9.3)
46+
webmock (1.21.0)
47+
addressable (>= 2.3.6)
48+
crack (>= 0.3.2)
4149

4250
PLATFORMS
4351
ruby

samples/client/petstore/ruby/lib/swagger/configuration.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class Configuration
99
def initialize
1010
@format = 'json'
1111
@scheme = 'http'
12-
@host = 'api.wordnik.com'
13-
@base_path = '/v4'
12+
@host = 'petstore.swagger.io'
13+
@base_path = '/v2'
1414
@user_agent = "ruby-swagger-#{Swagger::VERSION}"
15-
@inject_format = true
15+
@inject_format = false
1616
@force_ending_format = false
1717
@camelize_params = true
1818
end

samples/client/petstore/ruby/lib/swagger/request.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ def query_string
157157
end
158158

159159
def make
160-
logger = Logger.new STDOUT
161-
logger.debug self.url
160+
#TODO use configuration setting to determine if debugging
161+
#logger = Logger.new STDOUT
162+
#logger.debug self.url
162163
response = case self.http_method.to_sym
163164
when :get,:GET
164165
Typhoeus::Request.get(

samples/client/petstore/ruby/models/pet.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def self.attribute_map
1717
def initialize(attributes = {})
1818
return if attributes.empty?
1919
# Morph attribute keys into undescored rubyish style
20-
2120
if self.class.attribute_map[:"id"]
2221
@id = attributes["id"]
2322
end

samples/client/petstore/ruby/spec/pet_spec.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@
44
before do
55
Swagger.configure do |config|
66
config.api_key = 'special-key'
7-
config.host = 'petstore.swagger.wordnik.com'
8-
config.base_path = '/api'
7+
config.host = 'petstore.swagger.io'
8+
config.base_path = '/v2'
99
end
1010
end
1111

1212
describe "pet methods" do
1313
it "should fetch a pet object" do
14-
pet = Pet_api.get_pet_by_id(1)
15-
pet.id.should == 1
16-
pet.name.should == "Cat 1"
14+
pet = PetApi.getPetById(5)
15+
pet.id.should == 5
16+
pet.name.should == "Dog 2"
1717
end
1818

1919
it "should find pets by status" do
20-
pets = Pet_api.find_pets_by_status('available')
20+
pets = PetApi.findPetsByStatus('available')
2121
pets.length.should >= 3
2222
end
2323

2424
it "should not find a pet with invalid status" do
25-
pets = Pet_api.find_pets_by_status('dead')
25+
pets = PetApi.findPetsByStatus('dead')
2626
pets.length.should == 0
2727
end
2828

2929
it "should find a pet by status" do
30-
pets = Pet_api.find_pets_by_status("available,sold")
30+
pets = PetApi.findPetsByStatus("available,sold")
3131
pets.map {|pet|
3232
if(pet.status != 'available' && pet.status != 'sold')
3333
raise "pet status wasn't right"
@@ -36,19 +36,19 @@
3636
end
3737

3838
it "should update a pet" do
39-
pet = Pet.new({:id => 99, :name => 'programmer', :status => 'coding'})
40-
Pet_api.add_pet(pet)
39+
pet = Pet.new({'id' => 99, 'name' => 'programmer', 'status' => 'coding'})
40+
PetApi.addPet(pet)
4141

42-
fetched = Pet_api.get_pet_by_id(99)
42+
fetched = PetApi.getPetById(99)
4343
fetched.id.should == 99
4444
end
4545

4646
it "should create a pet" do
47-
pet = Pet.new({:id => 100, :name => "Gorilla"})
48-
raise pet.inspect
49-
Pet_api.add_pet(pet)
47+
pet = Pet.new('id' => 100, 'name' => "Gorilla")
48+
#raise pet.inspect
49+
PetApi.addPet(pet)
5050

51-
pet = Pet_api.get_pet_by_id(100)
51+
pet = PetApi.getPetById(100)
5252
pet.id.should == 100
5353
end
5454
end
@@ -58,13 +58,13 @@
5858
before do
5959
Swagger.configure do |config|
6060
config.api_key = 'special-key'
61-
config.host = 'petstore.swagger.wordnik.com'
62-
config.base_path = '/api'
61+
config.host = 'petstore.swagger.io'
62+
config.base_path = '/v2'
6363
end
6464
end
6565

6666
it "should fetch an order" do
67-
item = Store_api.get_order_by_id(1)
68-
item.id.should == 1
67+
item = StoreApi.getOrderById(2)
68+
item.id.should == 2
6969
end
70-
end
70+
end

samples/client/petstore/ruby/spec/request_spec.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
describe Swagger::Request do
44

5-
before(:each) do
5+
before(:each) do
6+
Swagger.configure do |config|
7+
inject_format = true
8+
config.api_key = 'special-key'
9+
config.host = 'petstore.swagger.io'
10+
config.base_path = '/v2'
11+
end
12+
613
@default_http_method = :get
7-
@default_path = "pet/fancy"
14+
@default_path = "pet.{format}/fancy"
815
@default_params = {
916
:params => {:foo => "1", :bar => "2"}
1017
}
@@ -44,7 +51,7 @@
4451
end
4552

4653
it "constructs a full url" do
47-
@request.url.should == "http://petstore.swagger.wordnik.com/api/pet.json/fancy?bar=2&foo=1"
54+
@request.url.should == "http://petstore.swagger.io/v2/pet.json/fancy?bar=2&foo=1"
4855
end
4956

5057
end
@@ -66,13 +73,13 @@
6673
describe "path" do
6774

6875
it "accounts for a total absence of format in the path string" do
69-
@request = Swagger::Request.new(:get, "/word/{word}/entries", @default_params.merge({
76+
@request = Swagger::Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({
7077
:format => "xml",
7178
:params => {
7279
:word => "cat"
7380
}
7481
}))
75-
@request.url.should == "http://petstore.swagger.wordnik.com/api/word.xml/cat/entries"
82+
@request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries"
7683
end
7784

7885
it "does string substitution on path params" do
@@ -82,7 +89,7 @@
8289
:word => "cat"
8390
}
8491
}))
85-
@request.url.should == "http://petstore.swagger.wordnik.com/api/word.xml/cat/entries"
92+
@request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries"
8693
end
8794

8895
it "leaves path-bound params out of the query string" do
@@ -193,4 +200,4 @@
193200

194201
end
195202

196-
end
203+
end

samples/client/petstore/ruby/spec/response_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
before(:each) do
66

77
VCR.use_cassette('pet_resource', :record => :new_episodes) do
8-
@raw = Typhoeus::Request.get("http://petstore.swagger.wordnik.com/api/pet.json")
8+
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/5")
99
end
1010

1111
@response = Swagger::Response.new(@raw)
@@ -14,7 +14,7 @@
1414
describe "initialization" do
1515
it "sets body" do
1616
@response.body.class.should == Hash
17-
@response.body.has_key?('apis').should == true
17+
@response.body.has_key?('name').should == true
1818
end
1919

2020
it "sets code" do
@@ -35,7 +35,8 @@
3535

3636
it "recognizes xml" do
3737
VCR.use_cassette('xml_response_request', :record => :new_episodes) do
38-
@raw = Typhoeus::Request.get("http://petstore.swagger.wordnik.com/api/pet.xml")
38+
@raw = Typhoeus::Request.get("http://petstore.swagger.io/v2/pet/5",
39+
:headers => {'Accept'=> "application/xml"})
3940
end
4041
@response = Swagger::Response.new(@raw)
4142
@response.format.should == 'xml'
@@ -56,4 +57,4 @@
5657

5758
end
5859

59-
end
60+
end

samples/client/petstore/ruby/spec/spec_helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@
1414

1515
RSpec.configure do |config|
1616
# some (optional) config here
17+
config.expect_with :rspec do |c|
18+
c.syntax = :should
19+
end
20+
config.mock_with :rspec do |c|
21+
c.syntax = :should
22+
end
1723
end
1824

25+
1926
WebMock.allow_net_connect! if defined? WebMock
2027

2128
def help

0 commit comments

Comments
 (0)