diff --git a/.gitignore b/.gitignore index 6aef647..0f96e1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ +*.gem +.bundle/ +.ruby-gemset .ruby-version Gemfile.lock -.bundle -vendor -*.gem -.DS_Store +coverage/ +vendor/ diff --git a/Gemfile b/Gemfile index e821ded..0fa2ea3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" +gem "coveralls", "0.7.0", require: false gem "rake", "10.1.1" gem "rspec", "2.14.1" -gem "webmock", "1.15.2" gem "vcr", "2.8.0" -gem "coveralls", "0.7.0", require: false +gem "webmock", "1.15.2" diff --git a/gw2.gemspec b/gw2.gemspec index afebeb3..34f8d10 100644 --- a/gw2.gemspec +++ b/gw2.gemspec @@ -1,7 +1,7 @@ Gem::Specification.new do |s| s.name = "gw2" - s.version = "1.2.0" - s.date = "2014-02-05" + s.version = "1.2.1" + s.date = "2014-09-06" s.summary = "Guild Wars 2 API" s.description = "A ruby gem for accessing the Guild Wars 2 API" s.authors = ["Chris Rosario"] diff --git a/lib/gw2.rb b/lib/gw2.rb index dc6f31f..81b8fdf 100644 --- a/lib/gw2.rb +++ b/lib/gw2.rb @@ -1,5 +1,4 @@ -require "gw2/json" -require "gw2/https" +require "gw2/api_request" require "gw2/event" require "gw2/wvw" require "gw2/item" diff --git a/lib/gw2/api_request.rb b/lib/gw2/api_request.rb new file mode 100644 index 0000000..90e6cbb --- /dev/null +++ b/lib/gw2/api_request.rb @@ -0,0 +1,20 @@ +require "gw2/https" +require "gw2/json" + +module GW2 + class ApiRequest + extend HTTPS + extend JSON + + def self.get(endpoint, query = {}) + path = endpoint_path(endpoint) + response = request(path, query: query) + parse(response) + end + + def self.endpoint_path(endpoint) + endpoint = Array(endpoint).join('/') + "/#{endpoint}.json" + end + end +end diff --git a/lib/gw2/event.rb b/lib/gw2/event.rb index 4b9422e..a1ba6e9 100644 --- a/lib/gw2/event.rb +++ b/lib/gw2/event.rb @@ -1,11 +1,23 @@ -require "gw2/event/event_names" -require "gw2/event/map_names" -require "gw2/event/world_names" -require "gw2/event/events" - module GW2 - module Event - extend HTTPS - extend JSON + class Event < ApiRequest + def self.all + where + end + + def self.where(query_hash = {}) + get :events, query_hash + end + + def self.event_names + get :event_names + end + + def self.map_names + get :map_names + end + + def self.world_names + get :world_names + end end end diff --git a/lib/gw2/event/event_names.rb b/lib/gw2/event/event_names.rb deleted file mode 100644 index c15a10d..0000000 --- a/lib/gw2/event/event_names.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Event - def self.event_names - parse(request("/event_names.json").body) - end - end -end diff --git a/lib/gw2/event/events.rb b/lib/gw2/event/events.rb deleted file mode 100644 index b29bdf4..0000000 --- a/lib/gw2/event/events.rb +++ /dev/null @@ -1,11 +0,0 @@ -module GW2 - module Event - def self.all - self.where - end - - def self.where(query_hash = {}) - parse(request("/events.json", query: query_hash).body) - end - end -end diff --git a/lib/gw2/event/map_names.rb b/lib/gw2/event/map_names.rb deleted file mode 100644 index 4a0fb1a..0000000 --- a/lib/gw2/event/map_names.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Event - def self.map_names - parse(request("/map_names.json").body) - end - end -end diff --git a/lib/gw2/event/world_names.rb b/lib/gw2/event/world_names.rb deleted file mode 100644 index d858607..0000000 --- a/lib/gw2/event/world_names.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Event - def self.world_names - parse(request("/world_names.json").body) - end - end -end diff --git a/lib/gw2/guild.rb b/lib/gw2/guild.rb index ecf0787..5b9d6c3 100644 --- a/lib/gw2/guild.rb +++ b/lib/gw2/guild.rb @@ -1,8 +1,7 @@ -require "gw2/guild/guild_details" - module GW2 - module Guild - extend HTTPS - extend JSON + class Guild < ApiRequest + def self.details(query_hash = {}) + get :guild_details, query_hash + end end end diff --git a/lib/gw2/guild/guild_details.rb b/lib/gw2/guild/guild_details.rb deleted file mode 100644 index ec97cb8..0000000 --- a/lib/gw2/guild/guild_details.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Guild - def self.details(query_hash = {}) - parse(request("/guild_details.json", query: query_hash).body) - end - end -end diff --git a/lib/gw2/https.rb b/lib/gw2/https.rb index 9fca804..6ad1b7b 100644 --- a/lib/gw2/https.rb +++ b/lib/gw2/https.rb @@ -1,8 +1,13 @@ -require "net/https" +require "open-uri" module GW2 module HTTPS - DEFAULT_REQUEST = { action: "Get", ssl: true } + DEFAULT_REQUEST = { action: "Get", ssl: true, query: {} } + + def endpoint_uri(endpoint, query = {}) + URI.parse(BASE_URL + endpoint + query_string(query)) + end + module_function :endpoint_uri def query_string(query_hash = {}) string = query_hash.collect{ |k,v| "#{k}=#{v}" }.join("&") @@ -10,22 +15,15 @@ def query_string(query_hash = {}) string end + module_function :query_string - def request(end_point = "", attr = {}) - attr = DEFAULT_REQUEST.merge(attr) - uri = URI.parse(BASE_URL + end_point + query_string(attr[:query] || {})) - - http = Net::HTTP.new(uri.host, uri.port) - http.use_ssl = attr[:ssl] - http.verify_mode = OpenSSL::SSL::VERIFY_NONE if attr[:ssl] # need to get a cert -_____- - - net_http = Net::HTTP - request = Net::HTTP.const_get(attr[:action]).new(uri.request_uri) - attr[:headers].each { |key, value| request[key.to_s] = value } if attr[:headers] + private - request.set_form_data(attr[:form_data]) if attr[:form_data] + def request(end_point, attr = {}) + attr = DEFAULT_REQUEST.merge(attr) + uri = endpoint_uri(end_point, attr[:query]) - http.request(request) + uri.read end end end diff --git a/lib/gw2/item.rb b/lib/gw2/item.rb index 0d2ba2b..3105004 100644 --- a/lib/gw2/item.rb +++ b/lib/gw2/item.rb @@ -1,9 +1,11 @@ -require "gw2/item/items" -require "gw2/item/item_details" - module GW2 - module Item - extend HTTPS - extend JSON + class Item < ApiRequest + def self.all + get :items + end + + def self.details(item_id) + get :item_details, item_id: item_id + end end end diff --git a/lib/gw2/item/item_details.rb b/lib/gw2/item/item_details.rb deleted file mode 100644 index 59bd84f..0000000 --- a/lib/gw2/item/item_details.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Item - def self.details(item_id) - parse(request("/item_details.json", query: { item_id: item_id }).body) - end - end -end diff --git a/lib/gw2/item/items.rb b/lib/gw2/item/items.rb deleted file mode 100644 index 87d7357..0000000 --- a/lib/gw2/item/items.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Item - def self.all - parse(request("/items.json").body) - end - end -end diff --git a/lib/gw2/map.rb b/lib/gw2/map.rb index 9491944..ddac75c 100644 --- a/lib/gw2/map.rb +++ b/lib/gw2/map.rb @@ -1,10 +1,19 @@ -require "gw2/map/continents" -require "gw2/map/maps" -require "gw2/map/map_floor" - module GW2 - module Map - extend HTTPS - extend JSON + class Map < ApiRequest + def self.all + where + end + + def self.where(query_hash = {}) + get :maps, query_hash + end + + def self.map_floor(continent_id, floor) + get :map_floor, continent_id: continent_id, floor: floor + end + + def self.continents + get :continents + end end end diff --git a/lib/gw2/map/continents.rb b/lib/gw2/map/continents.rb deleted file mode 100644 index d53fa93..0000000 --- a/lib/gw2/map/continents.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Map - def self.continents - parse(request("/continents.json").body) - end - end -end diff --git a/lib/gw2/map/map_floor.rb b/lib/gw2/map/map_floor.rb deleted file mode 100644 index b1c84a4..0000000 --- a/lib/gw2/map/map_floor.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Map - def self.map_floor(continent_id, floor) - parse(request("/map_floor.json", query: { continent_id: continent_id, floor: floor }).body) - end - end -end diff --git a/lib/gw2/map/maps.rb b/lib/gw2/map/maps.rb deleted file mode 100644 index 63db37e..0000000 --- a/lib/gw2/map/maps.rb +++ /dev/null @@ -1,13 +0,0 @@ -module GW2 - module Map - PARAMS_FILTER = [:map_id] - - def self.all - self.where - end - - def self.where(query_hash = {}) - parse(request("/maps.json", query: query_hash).body) - end - end -end diff --git a/lib/gw2/misc.rb b/lib/gw2/misc.rb index 8695ad9..7ad916b 100644 --- a/lib/gw2/misc.rb +++ b/lib/gw2/misc.rb @@ -1,10 +1,15 @@ -require "gw2/misc/build" -require "gw2/misc/colors" -require "gw2/misc/files" - module GW2 - module Misc - extend HTTPS - extend JSON + class Misc < ApiRequest + def self.build + get :build + end + + def self.colors + get :colors + end + + def self.files + get :files + end end end diff --git a/lib/gw2/misc/build.rb b/lib/gw2/misc/build.rb deleted file mode 100644 index 7d8c35a..0000000 --- a/lib/gw2/misc/build.rb +++ /dev/null @@ -1,8 +0,0 @@ -module GW2 - module Misc - def self.build - parse(request("/build.json").body) - end - end -end - diff --git a/lib/gw2/misc/colors.rb b/lib/gw2/misc/colors.rb deleted file mode 100644 index 9c1b173..0000000 --- a/lib/gw2/misc/colors.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Misc - def self.colors - parse(request("/colors.json").body) - end - end -end diff --git a/lib/gw2/misc/files.rb b/lib/gw2/misc/files.rb deleted file mode 100644 index dbc0e63..0000000 --- a/lib/gw2/misc/files.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Misc - def self.files - parse(request("/files.json").body) - end - end -end diff --git a/lib/gw2/recipe.rb b/lib/gw2/recipe.rb index 8a9b90d..c84e979 100644 --- a/lib/gw2/recipe.rb +++ b/lib/gw2/recipe.rb @@ -1,9 +1,11 @@ -require "gw2/recipe/recipes" -require "gw2/recipe/recipe_details" - module GW2 - module Recipe - extend HTTPS - extend JSON + class Recipe < ApiRequest + def self.all + get :recipes + end + + def self.details(recipe_id) + get :recipe_details, recipe_id: recipe_id + end end end diff --git a/lib/gw2/recipe/recipe_details.rb b/lib/gw2/recipe/recipe_details.rb deleted file mode 100644 index 0b415ff..0000000 --- a/lib/gw2/recipe/recipe_details.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Recipe - def self.details(recipe_id) - parse(request("/recipe_details.json", query: { recipe_id: recipe_id }).body) - end - end -end diff --git a/lib/gw2/recipe/recipes.rb b/lib/gw2/recipe/recipes.rb deleted file mode 100644 index ffbbbfb..0000000 --- a/lib/gw2/recipe/recipes.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module Recipe - def self.all - parse(request("/recipes.json").body) - end - end -end diff --git a/lib/gw2/wvw.rb b/lib/gw2/wvw.rb index 73767c6..2f6fc3c 100644 --- a/lib/gw2/wvw.rb +++ b/lib/gw2/wvw.rb @@ -1,10 +1,15 @@ -require "gw2/wvw/matches" -require "gw2/wvw/match_details" -require "gw2/wvw/objective_names" - module GW2 - module WvW - extend HTTPS - extend JSON + class WvW < ApiRequest + def self.matches + get [:wvw, :matches] + end + + def self.match_details(match_id) + get [:wvw, :match_details], match_id: match_id + end + + def self.objective_names + get [:wvw, :objective_names] + end end end diff --git a/lib/gw2/wvw/match_details.rb b/lib/gw2/wvw/match_details.rb deleted file mode 100644 index b5e3f0f..0000000 --- a/lib/gw2/wvw/match_details.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module WvW - def self.match_details(match_id) - parse(request("/wvw/match_details.json", query: { match_id: match_id }).body) - end - end -end diff --git a/lib/gw2/wvw/matches.rb b/lib/gw2/wvw/matches.rb deleted file mode 100644 index 817b649..0000000 --- a/lib/gw2/wvw/matches.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module WvW - def self.matches - parse(request("/wvw/matches.json").body) - end - end -end diff --git a/lib/gw2/wvw/objective_names.rb b/lib/gw2/wvw/objective_names.rb deleted file mode 100644 index 7a92ccb..0000000 --- a/lib/gw2/wvw/objective_names.rb +++ /dev/null @@ -1,7 +0,0 @@ -module GW2 - module WvW - def self.objective_names - parse(request("/wvw/objective_names.json").body) - end - end -end diff --git a/spec/event/event_names_spec.rb b/spec/event/event_names_spec.rb deleted file mode 100644 index 1736985..0000000 --- a/spec/event/event_names_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "spec_helper" - -describe GW2::Event do - describe "methods" do - context "#event_names" do - before :each do - @event_names = %Q([{"id":"7C2B9506-5C0C-49CA-9C73-3EA740772944","name":"Skill Challenge: Fight the Quaggan Pirate"}]) - - stub_request(:get, "https://api.guildwars2.com/v1/event_names.json"). - to_return(:status => 200, :body => @event_names) - end - - it "exists" do - GW2::Event.respond_to?(:event_names).should == true - end - - it "returns the correct data" do - GW2::Event.event_names.should == JSON.parse(@event_names) - end - end - end -end diff --git a/spec/event/events_spec.rb b/spec/event/events_spec.rb deleted file mode 100644 index 514e917..0000000 --- a/spec/event/events_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require "spec_helper" - -describe GW2::Event do - describe "methods" do - context "#all" do - before :each do - @events = [ - { "world_id" => 1013, "map_id" => 873, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537B", "state" => "Active" }, - { "world_id" => 1014, "map_id" => 874, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537C", "state" => "Success" }, - { "world_id" => 1015, "map_id" => 875, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537D", "state" => "Fail" }, - { "world_id" => 1016, "map_id" => 876, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537E", "state" => "Warmup" }, - { "world_id" => 1017, "map_id" => 877, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537F", "state" => "Preperation" } - ] - - stub_request(:get, "https://api.guildwars2.com/v1/events.json"). - to_return(:status => 200, :body => { "events" => @events }.to_json) - end - - it "exists" do - GW2::Event.respond_to?(:all).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Event.all.should == { "events" => @events } - end - end - - context "#events" do - before :each do - @events = [ - { "world_id" => 1013, "map_id" => 873, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537B", "state" => "Active" }, - { "world_id" => 1014, "map_id" => 874, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537C", "state" => "Success" }, - { "world_id" => 1015, "map_id" => 875, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537D", "state" => "Fail" }, - { "world_id" => 1016, "map_id" => 876, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537E", "state" => "Warmup" }, - { "world_id" => 1017, "map_id" => 877, "event_id" => "659149D4-43EC-4DCB-A6BB-0B2D402B537F", "state" => "Preperation" } - ] - - stub_request(:get, "https://api.guildwars2.com/v1/events.json?world_id=1014"). - to_return(:status => 200, :body => { "events" => @events.select{ |n| n[:world_id] == 1014 } }.to_json) - stub_request(:get, "https://api.guildwars2.com/v1/events.json?map_id=875"). - to_return(:status => 200, :body => { "events" => @events.select{ |n| n[:map_id] == 875 } }.to_json) - stub_request(:get, "https://api.guildwars2.com/v1/events.json?event_id=875"). - to_return(:status => 200, :body => { "events" => @events.select{ |n| n[:event_id] == "659149D4-43EC-4DCB-A6BB-0B2D402B537E" } }.to_json) - end - - it "exists" do - GW2::Event.respond_to?(:where).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Event.where(world_id: 1014).should == { "events" => @events.select{ |n| n[:world_id] == 1014 } } - end - end - end -end diff --git a/spec/event/map_names_spec.rb b/spec/event/map_names_spec.rb deleted file mode 100644 index 23f30c2..0000000 --- a/spec/event/map_names_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "spec_helper" - -describe GW2::Event do - describe "methods" do - context "#map_names" do - before :each do - @map_names = %Q([{"id":"15","name":"Queensdale"}]) - - stub_request(:get, "https://api.guildwars2.com/v1/map_names.json"). - to_return(:status => 200, :body => @map_names) - end - - it "exists" do - GW2::Event.respond_to?(:map_names).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Event.map_names.should == JSON.parse(@map_names) - end - end - end -end diff --git a/spec/event/world_names_spec.rb b/spec/event/world_names_spec.rb deleted file mode 100644 index b5a68c1..0000000 --- a/spec/event/world_names_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "spec_helper" - -describe GW2::Event do - describe "methods" do - context "#world_names" do - before :each do - @world_names = %Q([{"id":"1004","name":"Henge of Denravi"}]) - - stub_request(:get, "https://api.guildwars2.com/v1/world_names.json"). - to_return(:status => 200, :body => @world_names) - end - - it "exists" do - GW2::Event.respond_to?(:world_names).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Event.world_names.should == JSON.parse(@world_names) - end - end - end -end diff --git a/spec/guild/guild_details_spec.rb b/spec/guild/guild_details_spec.rb deleted file mode 100644 index 0e59b38..0000000 --- a/spec/guild/guild_details_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require "spec_helper" - -describe GW2::Guild do - describe "methods" do - context "#details" do - before :each do - @guild_details = { - "guild_id" => "16DB5921-CF1B-48D2-A5A0-2F0AADD9765D", - "guild_name" => "Ruinous", - "tag" => "RUIN", - "emblem" => { - "background_id" => 8, - "foreground_id" => 21, - "flags" => [], - "background_color_id" => 473, - "foreground_primary_color" => 146, - "foreground_seconary_color" => 146 - } - } - - stub_request(:get, "https://api.guildwars2.com/v1/guild_details.json?guild_id=16DB5921-CF1B-48D2-A5A0-2F0AADD9765D"). - to_return(:status => 200, :body => @guild_details.to_json) - stub_request(:get, "https://api.guildwars2.com/v1/guild_details.json?guild_name=Ruinous"). - to_return(:status => 200, :body => @guild_details.to_json) - end - - it "exists" do - GW2::Guild.respond_to?(:details).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Guild.details(guild_id: "16DB5921-CF1B-48D2-A5A0-2F0AADD9765D").should == @guild_details - GW2::Guild.details(guild_name: "Ruinous").should == @guild_details - end - end - end -end diff --git a/spec/gw2/event_spec.rb b/spec/gw2/event_spec.rb new file mode 100644 index 0000000..4e3318e --- /dev/null +++ b/spec/gw2/event_spec.rb @@ -0,0 +1,55 @@ +require "spec_helper" + +describe GW2::Event do + describe ".all" do + let(:endpoint) { "/events.json" } + subject(:parsed_result) { GW2::Event.all } + + include_examples "an API response parser" + end + + describe ".where" do + context "filtering by a world ID" do + let(:endpoint) { "/events.json?world_id=1014" } + subject(:parsed_result) { GW2::Event.where(world_id: 1014) } + + include_examples "an API response parser" + end + + context "filtering by a map ID" do + let(:endpoint) { "/events.json?map_id=875" } + subject(:parsed_result) { GW2::Event.where(map_id: 875) } + + include_examples "an API response parser" + end + + context "filtering by an event ID" do + let(:event_id) { "659149D4-43EC-4DCB-A6BB-0B2D402B537E" } + let(:endpoint) { "/events.json?event_id=#{event_id}" } + subject(:parsed_result) { GW2::Event.where(event_id: event_id) } + + include_examples "an API response parser" + end + end + + describe ".event_names" do + let(:endpoint) { "/event_names.json" } + subject(:parsed_result) { GW2::Event.event_names } + + include_examples "an API response parser" + end + + describe ".map_names" do + let(:endpoint) { "/map_names.json" } + subject(:parsed_result) { GW2::Event.map_names } + + include_examples "an API response parser" + end + + describe ".world_names" do + let(:endpoint) { "/world_names.json" } + subject(:parsed_result) { GW2::Event.world_names } + + include_examples "an API response parser" + end +end diff --git a/spec/gw2/guild_spec.rb b/spec/gw2/guild_spec.rb new file mode 100644 index 0000000..dc6ae94 --- /dev/null +++ b/spec/gw2/guild_spec.rb @@ -0,0 +1,21 @@ +require "spec_helper" + +describe GW2::Guild do + describe ".details" do + context "looking up details by guild ID" do + let(:guild_id) { "16DB5921-CF1B-48D2-A5A0-2F0AADD9765D" } + let(:endpoint) { "/guild_details.json?guild_id=#{guild_id}" } + subject(:parsed_result) { GW2::Guild.details(guild_id: guild_id) } + + include_examples "an API response parser" + end + + context "looking up details by guild name" do + let(:guild_name) { "Ruinous" } + let(:endpoint) { "/guild_details.json?guild_name=#{guild_name}" } + subject(:parsed_result) { GW2::Guild.details(guild_name: guild_name) } + + include_examples "an API response parser" + end + end +end diff --git a/spec/gw2/item_spec.rb b/spec/gw2/item_spec.rb new file mode 100644 index 0000000..d72e8d7 --- /dev/null +++ b/spec/gw2/item_spec.rb @@ -0,0 +1,17 @@ +require "spec_helper" + +describe GW2::Item do + describe ".all" do + let(:endpoint) { "/items.json" } + subject(:parsed_result) { GW2::Item.all } + + include_examples "an API response parser" + end + + describe ".details" do + let(:endpoint) { "/item_details.json?item_id=12546" } + subject(:parsed_result) { GW2::Item.details(12546) } + + include_examples "an API response parser" + end +end diff --git a/spec/gw2/map_spec.rb b/spec/gw2/map_spec.rb new file mode 100644 index 0000000..5fb34af --- /dev/null +++ b/spec/gw2/map_spec.rb @@ -0,0 +1,31 @@ +require "spec_helper" + +describe GW2::Map do + describe ".all" do + let(:endpoint) { "/maps.json" } + subject(:parsed_result) { GW2::Map.all } + + include_examples "an API response parser" + end + + describe ".where" do + let(:endpoint) { "/maps.json?map_id=80" } + subject(:parsed_result) { GW2::Map.where(map_id: 80) } + + include_examples "an API response parser" + end + + describe ".map_floor" do + let(:endpoint) { "/map_floor.json?continent_id=1&floor=1" } + subject(:parsed_result) { GW2::Map.map_floor(1, 1) } + + include_examples "an API response parser" + end + + describe ".continents" do + let(:endpoint) { "/continents.json" } + subject(:parsed_result) { GW2::Map.continents } + + include_examples "an API response parser" + end +end diff --git a/spec/gw2/misc_spec.rb b/spec/gw2/misc_spec.rb new file mode 100644 index 0000000..9dbf384 --- /dev/null +++ b/spec/gw2/misc_spec.rb @@ -0,0 +1,24 @@ +require "spec_helper" + +describe GW2::Misc do + describe ".build" do + let(:endpoint) { "/build.json" } + subject(:parsed_result) { GW2::Misc.build } + + include_examples "an API response parser" + end + + describe ".colors" do + let(:endpoint) { "/colors.json" } + subject(:parsed_result) { GW2::Misc.colors } + + include_examples "an API response parser" + end + + describe ".files" do + let(:endpoint) { "/files.json" } + subject(:parsed_result) { GW2::Misc.files } + + include_examples "an API response parser" + end +end diff --git a/spec/gw2/recipe_spec.rb b/spec/gw2/recipe_spec.rb new file mode 100644 index 0000000..964ff8a --- /dev/null +++ b/spec/gw2/recipe_spec.rb @@ -0,0 +1,17 @@ +require "spec_helper" + +describe GW2::Recipe do + describe ".all" do + let(:endpoint) { "/recipes.json" } + subject(:parsed_result) { GW2::Recipe.all } + + include_examples "an API response parser" + end + + describe ".details" do + let(:endpoint) { "/recipe_details.json?recipe_id=1275" } + subject(:parsed_result) { GW2::Recipe.details(1275) } + + include_examples "an API response parser" + end +end diff --git a/spec/gw2/wvw_spec.rb b/spec/gw2/wvw_spec.rb new file mode 100644 index 0000000..70bba58 --- /dev/null +++ b/spec/gw2/wvw_spec.rb @@ -0,0 +1,24 @@ +require "spec_helper" + +describe GW2::WvW do + describe ".matches" do + let(:endpoint) { "/wvw/matches.json" } + subject(:parsed_result) { GW2::WvW.matches } + + include_examples "an API response parser" + end + + describe ".match_details" do + let(:endpoint) {"/wvw/match_details.json?match_id=2-3"} + subject(:parsed_result) { GW2::WvW.match_details("2-3") } + + include_examples "an API response parser" + end + + describe ".objective_names" do + let(:endpoint) { "/wvw/objective_names.json" } + subject(:parsed_result) { GW2::WvW.objective_names } + + include_examples "an API response parser" + end +end diff --git a/spec/item/item_details_spec.rb b/spec/item/item_details_spec.rb deleted file mode 100644 index 6d25f47..0000000 --- a/spec/item/item_details_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require "spec_helper" - -describe GW2::Item do - describe "methods" do - context "#details" do - before :each do - @item_details = { - "item_id" => "12546", - "name" => "Lemongrass", - "description" => "Ingredient", - "type" => "CraftingMaterial", - "level" => "80", - "rarity" => "Basic", - "vendor_value" => "9", - "game_types" => ["Activity","Dungeon","Pve","Wvw"], - "flags" => [], - "restrictions" => [], - "crafting_material" => "" - } - - stub_request(:get, "https://api.guildwars2.com/v1/item_details.json?item_id=12546"). - to_return(:status => 200, :body => @item_details.to_json) - end - - it "exists" do - GW2::Item.respond_to?(:details).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Item.details(12546).should == @item_details - end - end - end -end diff --git a/spec/item/items_spec.rb b/spec/item/items_spec.rb deleted file mode 100644 index 01210a3..0000000 --- a/spec/item/items_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "spec_helper" - -describe GW2::Item do - describe "methods" do - context "#all" do - before :each do - @items = [12546, 12547, 12548, 12549, 12550] - - stub_request(:get, "https://api.guildwars2.com/v1/items.json"). - to_return(:status => 200, :body => { "items" => @items }.to_json) - end - - it "exists" do - GW2::Item.respond_to?(:all).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Item.all.should == { "items" => @items } - end - end - end -end diff --git a/spec/map/continents_spec.rb b/spec/map/continents_spec.rb deleted file mode 100644 index dfea6ed..0000000 --- a/spec/map/continents_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require "spec_helper" - -describe GW2::Map do - describe "methods" do - context "#continents" do - before :each do - @continents = { - "1" => { - "name" => "Tyria", - "continent_dims" => [ 32768, 32768 ], - "min_zoom" => 0, - "max_zoom" => 7, - "floors" => [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 30, -2, -3, -4, -5, -6, -7, -8, -10, -11, -15, -16, -17, 38, - 20, 21, 22, 23, 24, 25, 26, 27, 34, 36, 37 ] - }, - "2" => { - "name" => "Mists", - "continent_dims" => [ 16384, 16384 ], - "min_zoom" => 0, - "max_zoom" => 6, - "floors" => [ 1, 3, 5, 6, 7, 8, 9, 10, 13, 14, 18, 19, 21, 22, 23, 24, 25, - 26, -27, -28, -29, -30, -31, -32, -33, 27 ] - } - } - - stub_request(:get, "https://api.guildwars2.com/v1/continents.json"). - to_return(:status => 200, :body => { "continents" => @continents }.to_json) - end - - it "exists" do - GW2::Map.respond_to?(:continents).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Map.continents.should == { "continents" => @continents } - end - end - end -end diff --git a/spec/map/map_floor_spec.rb b/spec/map/map_floor_spec.rb deleted file mode 100644 index ea6e73b..0000000 --- a/spec/map/map_floor_spec.rb +++ /dev/null @@ -1,76 +0,0 @@ -require "spec_helper" - -describe GW2::Map do - describe "methods" do - context "#map_floor" do - before :each do - @floors = { - "texture_dims" => [ 32768, 32768 ], - "regions" => { - "1" => { - "name" => "Shiverpeak Mountains", - "label_coord" => [ 19840, 13568 ], - "maps" => { - "31" => { - "name" => "Snowden Drifts", - "min_level" => 15, - "max_level" => 25, - "default_floor" => 1, - "map_rect" => [ - [ -49152, -24576 ], - [ 49152, 24576 ] - ], - "continent_rect" => [ - [ 17664, 11264 ], - [ 21760, 13312 ] - ], - "points_of_interest" => [ - { - "poi_id" => 164, - "name" => "Blasted Haven", - "type" => "landmark", - "floor" => 1, - "coord" => [ 20768.5, 11893.5 ] - } - ], - "tasks" => [ - { - "task_id" => 28, - "objective" => "Help hunters and travelers near the road.", - "level" => 15, - "coord" => [ 21326.4, 11982.8 ] - } - ], - "skill_challenges" => [ - { - "coord" => [ 18922.3, 11445.5 ] - } - ], - "sectors" => [ - { - "sector_id" => 1015, - "name" => "King Jalis's Refuge", - "level" => 19, - "coord" => [ 21673.8, 12111.8 ] - } - ] - }, - } - } - } - } - - stub_request(:get, "https://api.guildwars2.com/v1/map_floor.json?continent_id=1&floor=1"). - to_return(:status => 200, :body => @floors.to_json) - end - - it "exists" do - GW2::Map.respond_to?(:map_floor).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Map.map_floor(1, 1).should == @floors - end - end - end -end diff --git a/spec/map/maps_spec.rb b/spec/map/maps_spec.rb deleted file mode 100644 index 5d71622..0000000 --- a/spec/map/maps_spec.rb +++ /dev/null @@ -1,79 +0,0 @@ -require "spec_helper" - -describe GW2::Map do - describe "methods" do - context "#all" do - before :each do - @maps = { - "80" => { - "map_name" => "A Society Function", - "min_level" => 8, - "max_level" => 8, - "default_floor" => 1, - "floors" => [1, 2], - "region_id" => 8, - "region_name" => "Steamspur Mountains", - "continent_id" => 1, - "continent_name" => "Tyria", - "map_rect" => [ - [-21504, -21504], - [24576, 21504] - ], - "continent_rect" => [ - [10240, 9856], - [12160, 11648] - ] - } - } - - stub_request(:get, "https://api.guildwars2.com/v1/maps.json"). - to_return(:status => 200, :body => { "maps" => @maps }.to_json) - end - - it "exists" do - GW2::Map.respond_to?(:all).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Map.all.should == { "maps" => @maps } - end - end - - context "#maps" do - before :each do - @maps = { - "80" => { - "map_name" => "A Society Function", - "min_level" => 8, - "max_level" => 8, - "default_floor" => 1, - "floors" => [1, 2], - "region_id" => 8, - "region_name" => "Steamspur Mountains", - "continent_id" => 1, - "continent_name" => "Tyria", - "map_rect" => [ - [-21504, -21504], - [24576, 21504] - ], - "continent_rect" => [ - [10240, 9856], - [12160, 11648] - ] - } - } - - stub_request(:get, "https://api.guildwars2.com/v1/maps.json?map_id=80"). - to_return(:status => 200, :body => { "maps" => @maps }.to_json) - end - - it "exists" do - GW2::Map.respond_to?(:where).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Map.where(map_id: 80).should == { "maps" => @maps } - end - end - end -end diff --git a/spec/misc/build_spec.rb b/spec/misc/build_spec.rb deleted file mode 100644 index e33d95e..0000000 --- a/spec/misc/build_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "spec_helper" - -describe GW2::Misc do - describe "methods" do - context "#build" do - before :each do - @build = { "build_id" => 22120 } - - stub_request(:get, "https://api.guildwars2.com/v1/build.json"). - to_return(:status => 200, :body => @build.to_json) - end - - it "exists" do - GW2::Misc.respond_to?(:build).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Misc.build.should == @build - end - end - end -end \ No newline at end of file diff --git a/spec/misc/colors_spec.rb b/spec/misc/colors_spec.rb deleted file mode 100644 index d36b05c..0000000 --- a/spec/misc/colors_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require "spec_helper" - -describe GW2::Misc do - describe "methods" do - context "#colors" do - before :each do - @colors = { - "126" => { - "name" => "Hot Pink", - "base_rgb" => [ 128, 26, 26 ], - "cloth" => { - "brightness" => 14, - "contrast" => 1.21094, - "hue" => 340, - "saturation" => 0.820313, - "lightness" => 1.44531, - "rgb" => [ 169, 54, 94 ] - }, - "leather" => { - "brightness" => 14, - "contrast" => 1.21094, - "hue" => 340, - "saturation" => 0.703125, - "lightness" => 1.44531, - "rgb" => [ 160, 62, 96 ] - }, - "metal" => { - "brightness" => 14, - "contrast" => 1.21094, - "hue" => 340, - "saturation" => 0.585938, - "lightness" => 1.44531, - "rgb" => [ 151, 69, 98 ] - } - } - } - - stub_request(:get, "https://api.guildwars2.com/v1/colors.json"). - to_return(:status => 200, :body => { "colors" => @colors }.to_json) - end - - it "exists" do - GW2::Misc.respond_to?(:colors).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Misc.colors.should == { "colors" => @colors } - end - end - end -end diff --git a/spec/misc/files_spec.rb b/spec/misc/files_spec.rb deleted file mode 100644 index 7155706..0000000 --- a/spec/misc/files_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require "spec_helper" - -describe GW2::Misc do - describe "methods" do - context "#files" do - before :each do - @files = { - "map_complete" => { "file_id" => 528724, "signature" => "5A4E663071250EC72668C09E3C082E595A380BF7" }, - "map_dungeon" => { "file_id" => 102478, "signature" => "943538394A94A491C8632FBEF6203C2013443555" }, - "map_heart_empty" => { "file_id" => 102440, "signature" => "09ACBA53B7412CC3C76E7FEF39929843C20CB0E4" } - } - - stub_request(:get, "https://api.guildwars2.com/v1/files.json"). - to_return(:status => 200, :body => @files.to_json) - end - - it "exists" do - GW2::Misc.respond_to?(:files).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Misc.files.should == @files - end - end - end -end \ No newline at end of file diff --git a/spec/recipe/recipe_details_spec.rb b/spec/recipe/recipe_details_spec.rb deleted file mode 100644 index 1c732d7..0000000 --- a/spec/recipe/recipe_details_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -require "spec_helper" - -describe GW2::Recipe do - describe "methods" do - context "#details" do - before :each do - @recipe_details = { - "recipe_id" => "1275", - "type" => "Coat", - "output_item_id" => "11541", - "output_item_count" => "1", - "min_rating" => "25", - "time_to_craft_ms" => "1000", - "ingredients" => [ - {"item_id" => "19797","count" => "1"}, - {"item_id" => "13094","count" => "1"}, - {"item_id" => "13093","count" => "1"} - ] - } - - stub_request(:get, "https://api.guildwars2.com/v1/recipe_details.json?recipe_id=1275"). - to_return(:status => 200, :body => @recipe_details.to_json) - end - - it "exists" do - GW2::Recipe.respond_to?(:details).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Recipe.details(1275).should == @recipe_details - end - end - end -end diff --git a/spec/recipe/recipes_spec.rb b/spec/recipe/recipes_spec.rb deleted file mode 100644 index c92bcaa..0000000 --- a/spec/recipe/recipes_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require "spec_helper" - -describe GW2::Recipe do - describe "methods" do - context "#all" do - before :each do - @recipes = [1275, 1276, 1277, 1278, 1279] - - stub_request(:get, "https://api.guildwars2.com/v1/recipes.json"). - to_return(:status => 200, :body => { "recipes" => @recipes }.to_json) - end - - it "exists" do - GW2::Recipe.respond_to?(:all).should == true - end - - it "returns the correct JSON parsed data" do - GW2::Recipe.all.should == { "recipes" => @recipes } - end - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d3c8f54..7551459 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ require "webmock/rspec" require "coveralls" require "gw2" +Dir["./spec/support/**/*.rb"].sort.each { |f| require f } RSpec.configure do |config| # ## Mock Framework @@ -16,6 +17,8 @@ # examples within a transaction, remove the following line or assign false # instead of true. # config.use_transactional_fixtures = false + + config.include ApiHelper end Coveralls.wear! diff --git a/spec/support/api_helper.rb b/spec/support/api_helper.rb new file mode 100644 index 0000000..330436c --- /dev/null +++ b/spec/support/api_helper.rb @@ -0,0 +1,9 @@ +module ApiHelper + def endpoint_uri(*args) + GW2::HTTPS.endpoint_uri(*args) + end + + def stub_endpoint(endpoint) + stub_request :get, endpoint_uri(endpoint) + end +end diff --git a/spec/support/api_response_parser_examples.rb b/spec/support/api_response_parser_examples.rb new file mode 100644 index 0000000..f64794a --- /dev/null +++ b/spec/support/api_response_parser_examples.rb @@ -0,0 +1,17 @@ +shared_examples "an API response parser" do + let(:response_body) { sample_data.to_json } + + let(:sample_data) do + [ + { "String" => "By Ogden's Hammer, What Savings!" }, + { "Integer" => 42 }, + { "Array" => ["Chauncy von Snuffles III", 9001] }, + { "Hash" => { "Chauncy von Snuffles III" => 9001 } }, + ] + end + + it "returns the correct JSON parsed data" do + stub_endpoint(endpoint).to_return(body: response_body) + parsed_result.should == sample_data + end +end diff --git a/spec/wvw/match_details_spec.rb b/spec/wvw/match_details_spec.rb deleted file mode 100644 index 9f52c98..0000000 --- a/spec/wvw/match_details_spec.rb +++ /dev/null @@ -1,108 +0,0 @@ -require "spec_helper" - -describe GW2::WvW do - describe "methods" do - context "#match_details" do - before :each do - @match_details = { - "match_id" => "2-3", - "scores" => [155221,151605,162092], - "maps" => [ - { "type" => "RedHome", - "scores" => [59573,23796,18316], - "objectives" => [ - {"id" => 32,"owner" => "Blue"}, - {"id" => 33,"owner" => "Blue"}, - {"id" => 34,"owner" => "Blue"}, - {"id" => 35,"owner" => "Blue"}, - {"id" => 36,"owner" => "Blue"}, - {"id" => 37,"owner" => "Blue","owner_guild" => "199C1F0E-AD62-4FF4-BE56-1189FFB8A89A"}, - {"id" => 38,"owner" => "Red"}, - {"id" => 39,"owner" => "Blue"}, - {"id" => 40,"owner" => "Blue"}, - {"id" => 50,"owner" => "Blue","owner_guild" => "E5E16465-4CB5-494A-8990-B893C46B527E"}, - {"id" => 51,"owner" => "Blue"}, - {"id" => 52,"owner" => "Red"}, - {"id" => 53,"owner" => "Blue"} - ] - }, - { "type" => "GreenHome", - "scores" => [20680,26330,52579], - "objectives" => [ - {"id" => 41,"owner" => "Blue"}, - {"id" => 42,"owner" => "Blue"}, - {"id" => 43,"owner" => "Blue"}, - {"id" => 44,"owner" => "Blue","owner_guild" => "6E884D81-3E34-46EE-85A1-91BE902D5522"}, - {"id" => 45,"owner" => "Blue","owner_guild" => "ABBD0F2A-DD9F-4496-9AD2-CFBB9958DA11"}, - {"id" => 46,"owner" => "Blue","owner_guild" => "3BADBA61-A0FC-47A8-8558-26591049C9CD"}, - {"id" => 47,"owner" => "Green","owner_guild" => "7FE25AEC-96B8-46A9-88B1-9B99ABF42F40"}, - {"id" => 48,"owner" => "Blue"}, - {"id" => 49,"owner" => "Blue","owner_guild" => "F7BE2E79-87F6-441A-96AC-F66075668102"}, - {"id" => 54,"owner" => "Red"}, - {"id" => 55,"owner" => "Red"}, - {"id" => 56,"owner" => "Blue"}, - {"id" => 57,"owner" => "Blue"} - ] - }, - { "type" => "BlueHome", - "scores" => [27092,55872,17878], - "objectives" => [ - {"id" => 23,"owner" => "Blue"}, - {"id" => 24,"owner" => "Red"}, - {"id" => 25,"owner" => "Blue"}, - {"id" => 26,"owner" => "Blue"}, - {"id" => 27,"owner" => "Blue"}, - {"id" => 28,"owner" => "Blue"}, - {"id" => 29,"owner" => "Blue","owner_guild" => "AEA6CFB4-9378-4548-831E-01110EFB1619"}, - {"id" => 30,"owner" => "Blue"}, - {"id" => 31,"owner" => "Blue"}, - {"id" => 58,"owner" => "Blue"}, - {"id" => 59,"owner" => "Blue"}, - {"id" => 60,"owner" => "Red"}, - {"id" => 61,"owner" => "Red"} - ] - }, - { "type" => "Center", - "scores" => [47876,45607,73319], - "objectives" => [ - {"id" => 1,"owner" => "Red","owner_guild" => "0E59E334-5F87-46A5-8CC8-6953AE5FC16A"}, - {"id" => 2,"owner" => "Blue","owner_guild" => "F36CC3FE-4F8B-486B-B5E1-D725119505F8"}, - {"id" => 3,"owner" => "Green","owner_guild" => "634BB549-B013-44BF-8915-2075DCA94062"}, - {"id" => 4,"owner" => "Green"}, - {"id" => 5,"owner" => "Blue"}, - {"id" => 6,"owner" => "Red"}, - {"id" => 7,"owner" => "Green","owner_guild" => "CF02A8AE-EC30-4377-9897-CC8EEC12050B"}, - {"id" => 8,"owner" => "Blue"}, - {"id" => 9,"owner" => "Blue","owner_guild" => "61B7040B-C243-4BB5-934C-C60AF0AD9FAE"}, - {"id" => 10,"owner" => "Green"}, - {"id" => 11,"owner" => "Green","owner_guild" => "390ABFA1-BB45-47F1-BBF9-EA4213FD8F76"}, - {"id" => 12,"owner" => "Green","owner_guild" => "C4D66309-DB0B-4CE1-A97E-B0C587C65994"}, - {"id" => 13,"owner" => "Green","owner_guild" => "71F44932-2DAA-4406-A705-AC4C557E57D1"}, - {"id" => 14,"owner" => "Green","owner_guild" => "D4BDDB21-CCB4-4838-94B8-170457AAB623"}, - {"id" => 15,"owner" => "Blue","owner_guild" => "7847823D-FB01-43FF-A7C2-DC0F0D12D4E7"}, - {"id" => 16,"owner" => "Blue","owner_guild" => "D12DB7AD-01FD-41F2-AE08-19A92AA05F6D"}, - {"id" => 17,"owner" => "Red"}, - {"id" => 18,"owner" => "Blue"}, - {"id" => 19,"owner" => "Red","owner_guild" => "EDA9DED3-8FA9-4B29-8787-06ED031238AA"}, - {"id" => 20,"owner" => "Red","owner_guild" => "75DC0FD9-7134-41E5-BBDA-6E620DF364B2"}, - {"id" => 21,"owner" => "Blue"}, - {"id" => 22,"owner" => "Blue","owner_guild" => "77A3A76E-A852-45FE-BA23-3A1F7847E8AC"} - ] - } - ] - } - - stub_request(:get, "https://api.guildwars2.com/v1/wvw/match_details.json?match_id=2-3"). - to_return(:status => 200, :body => @match_details.to_json) - end - - it "exists" do - GW2::WvW.respond_to?(:match_details).should == true - end - - it "returns the correct JSON parsed data" do - GW2::WvW.match_details("2-3").should == @match_details - end - end - end -end diff --git a/spec/wvw/matches_spec.rb b/spec/wvw/matches_spec.rb deleted file mode 100644 index 659748f..0000000 --- a/spec/wvw/matches_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require "spec_helper" - -describe GW2::WvW do - describe "methods" do - context "#matches" do - before :each do - @matches = [ - { "wvw_match_id" => "2-3", "red_world_id" => 2103, "blue_world_id" => 2301, "green_world_id" => 2012 }, - { "wvw_match_id" => "2-2", "red_world_id" => 2201, "blue_world_id" => 2010, "green_world_id" => 2101 } - ] - - stub_request(:get, "https://api.guildwars2.com/v1/wvw/matches.json"). - to_return(:status => 200, :body => { "wvw_matches" => @matches }.to_json) - end - - it "exists" do - GW2::WvW.respond_to?(:matches).should == true - end - - it "returns the correct JSON parsed data" do - GW2::WvW.matches.should == { "wvw_matches" => @matches } - end - end - end -end diff --git a/spec/wvw/objective_names_spec.rb b/spec/wvw/objective_names_spec.rb deleted file mode 100644 index e77f40c..0000000 --- a/spec/wvw/objective_names_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require "spec_helper" - -describe GW2::WvW do - describe "methods" do - context "#objective_names" do - before :each do - @objective_names = [ - {"id" => "30","name" => "Tower"}, - {"id" => "57","name" => "Tower"} - ] - - stub_request(:get, "https://api.guildwars2.com/v1/wvw/objective_names.json"). - to_return(:status => 200, :body => @objective_names.to_json) - end - - it "exists" do - GW2::WvW.respond_to?(:objective_names).should == true - end - - it "returns the correct data" do - GW2::WvW.objective_names.should == @objective_names - end - end - end -end