Browse files

Added what I have for spec so far

  • Loading branch information...
1 parent 6501580 commit b293d90ff84baac1cc4ab6f2be3cb9b03130e822 @fixlr fixlr committed Jul 13, 2008
View
53 spec/nikeplus/http_response_spec.rb
@@ -0,0 +1,53 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe "NikePlus::HttpResponse" do
+
+ it "should raise an error if the response status cannot be retrieved" do
+ r = create_response('bad_response.xml')
+ lambda {
+ r.success?
+ }.should raise_error
+ end
+
+ it "should recognize failure response status" do
+ r = create_response('loginFailed.xml')
+ r.success?.should be_false
+ end
+
+ it "should recognize the error code after a failure" do
+ r = create_response('loginFailed.xml')
+ r.error_code.should == 'invalidPassword'
+ end
+
+ it "should recognize the error message after a failure" do
+ r = create_response('loginFailed.xml')
+ r.error_message.should == 'The password is incorrect'
+ end
+
+
+ it "should recognize successful response status" do
+ r = create_response('login_successful.xml')
+ r.success?.should be_true
+ end
+
+ it "should be able to fetch an element from the response" do
+ r = create_response('login_successful.xml')
+ r.fetch('profile/id').text.should == '123456'
+ end
+
+ it "should raise an error if the fetched element does not exist" do
+ r = create_response('login_successful.xml')
+ lambda {
+ r.fetch('profile/bacon').text
+ }.should raise_error
+ end
+
+ private
+ def create_response(xml_file)
+ raw_response = mock("RawResponse")
+ raw_response.should_receive(:fetch).with('set-cookie').and_return("COOKIE")
+ raw_response.should_receive(:body).and_return(File.read(File.dirname(__FILE__) + "/../xml/#{xml_file}"))
+
+ NikePlus::HttpResponse.new(raw_response)
+ end
+end
View
6 spec/nikeplus/session_spec.rb
@@ -0,0 +1,6 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe "NikePlus::Session" do
+
+ # TODO: Haven't figured out testing of the Net::HTTP operations yet...
+end
View
8 spec/nikeplus_spec.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/spec_helper'
+
+# TODO: wtf should I do here... hmmm.
+describe "NikePlus" do
+ it "should not fail" do
+ true
+ end
+end
View
14 spec/spec_helper.rb
@@ -0,0 +1,14 @@
+require 'rubygems'
+require 'spec'
+require File.dirname(__FILE__) + '/../lib/nikeplus'
+
+Spec::Runner.configure do |config|
+ # == Mock Framework
+ #
+ # RSpec uses it's own mocking framework by default. If you prefer to
+ # use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+end
View
1 spec/xml/bad_response.xml
@@ -0,0 +1 @@
+<xml></xml>
View
4 spec/xml/empty_challenge_list.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plusService>
+ <challengeList/>
+</plusService>
View
5 spec/xml/failed_challenge_request.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plusService>
+ <status>failure</status>
+ <serviceException errorCode="RequestParametersError">missing id parameter</serviceException>
+</plusService>
View
5 spec/xml/failed_run_request.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plusService>
+ <status>failure</status>
+ <serviceException errorCode="RequestParametersError">no id parameter in request</serviceException>
+</plusService>
View
36 spec/xml/get_user_data.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plusService>
+ <status>success</status>
+ <user id="123456">
+ <status>confirmed</status>
+ <gender>male</gender>
+ <email>john@example.com</email>
+ <state>XZ</state>
+ <city>Nowheresville</city>
+ <country>US</country>
+ </user>
+ <userTotals>
+ <totalDistance>39.9036</totalDistance>
+ <totalDuration>19864355</totalDuration>
+ <totalRuns>10</totalRuns>
+ <totalCalories>3921</totalCalories>
+ <totalWorkouts>0</totalWorkouts>
+ <totalCardioDistance>0.0</totalCardioDistance>
+ </userTotals>
+ <userOptions>
+ <screenName><![CDATA[example]]></screenName>
+ <distanceUnit>mi</distanceUnit>
+ <dateFormat>MM/DD/YY</dateFormat>
+ <startWeek>Mo</startWeek>
+ <avatar>4</avatar>
+ <uploadedAvatar/>
+ <isPublic>true</isPublic>
+ </userOptions>
+ <mostRecentRun id="654321" workoutType="standard">
+ <startTime>2008-07-10T18:57:39-04:00</startTime>
+ <distance>4.5511</distance>
+ <duration>2136862</duration>
+ <workoutType>standard</workoutType>
+ <equipment>ipod</equipment>
+ </mostRecentRun>
+</plusService>
View
18 spec/xml/goals_list.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plusService>
+ <status>success</status>
+ <goalList>
+ <goal id="2468">
+ <complete>false</complete>
+ <level>01</level>
+ <startTime>2008-07-05T17:12:30+00:00</startTime>
+ <endTime>2008-08-03T03:59:59+00:00</endTime>
+ <definition>
+ <type>runMoreOften</type>
+ <numberOfRuns>8</numberOfRuns>
+ <totalProgress>3</totalProgress>
+ </definition>
+ </goal>
+ </goalList>
+ <goalResolutionList/>
+</plusService>
View
13 spec/xml/loginFailed.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<profileService>
+ <status>failure</status>
+ <exceptions>
+ <error>
+ <errorcode>invalidPassword</errorcode>
+ <property></property>
+ <message>The password is incorrect</message>
+ </error>
+ <error></error>
+ </exceptions>
+ <profile></profile>
+</profileService>
View
36 spec/xml/login_successful.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<profileService>
+ <status>success</status>
+ <exceptions></exceptions>
+ <profile>
+ <id>123456</id>
+ <firstName>John</firstName>
+ <middleName></middleName>
+ <lastName>Smith</lastName>
+ <email>john@example.com</email>
+ <locale>en_US</locale>
+ <userType>0</userType>
+ <login>john@example.com</login>
+ <screenName></screenName>
+ <receiveEmail>false</receiveEmail>
+ <gender>male</gender>
+ <passwordQuestion>Favorite programming language</passwordQuestion>
+ <passwordAnswer>Ruby</passwordAnswer>
+ <registrationSiteId>1111</registrationSiteId>
+ <temporaryPassword>false</temporaryPassword>
+ <dobMonth>1</dobMonth>
+ <dobDay>1</dobDay>
+ <dobYear>1970</dobYear>
+ <mobileNumber>098-765-4321</mobileNumber>
+ <mobileCarrier>Bacon</mobileCarrier>
+ <mobileScreenName>Mynameisjohnsmith</mobileScreenName>
+ <homeAddress.address1>1234 Bluebird Lane</homeAddress.address1>
+ <homeAddress.address2>Apartment B</homeAddress.address2>
+ <homeAddress.address3>Bedroom 4</homeAddress.address3>
+ <homeAddress.city>Nowheresville</homeAddress.city>
+ <homeAddress.state>XZ</homeAddress.state>
+ <homeAddress.postalCode>99999</homeAddress.postalCode>
+ <homeAddress.country>US</homeAddress.country>
+ <homeAddress.phoneNumber>123-456-7890</homeAddress.phoneNumber>
+ </profile>
+</profileService>
View
96 spec/xml/runs_list.xml
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plusService>
+ <status>success</status>
+ <runList>
+ <run id="1" workoutType="standard">
+ <startTime>2008-05-17T16:27:33-04:00</startTime>
+ <distance>4.1564</distance>
+ <duration>2558375</duration>
+ <syncTime>2008-05-17T21:12:13+00:00</syncTime>
+ <calories>409</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ <run id="2" workoutType="standard">
+ <startTime>2008-05-18T10:35:27-04:00</startTime>
+ <distance>3.364</distance>
+ <duration>1488174</duration>
+ <syncTime>2008-05-19T11:54:22+00:00</syncTime>
+ <calories>331</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ <run id="3" workoutType="standard">
+ <startTime>2008-05-20T17:33:56-04:00</startTime>
+ <distance>3.8563</distance>
+ <duration>1893539</duration>
+ <syncTime>2008-05-21T12:40:49+00:00</syncTime>
+ <calories>380</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ <run id="4" workoutType="standard">
+ <startTime>2008-05-25T18:43:24-04:00</startTime>
+ <distance>3.7046</distance>
+ <duration>1883634</duration>
+ <syncTime>2008-05-27T18:41:01+00:00</syncTime>
+ <calories>365</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ <run id="5" workoutType="standard">
+ <startTime>2008-06-19T17:13:39-04:00</startTime>
+ <distance>4.543</distance>
+ <duration>2249197</duration>
+ <syncTime>2008-06-27T12:27:36+00:00</syncTime>
+ <calories>447</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ <run id="6" workoutType="standard">
+ <startTime>2008-06-23T18:22:28-04:00</startTime>
+ <distance>3.8601</distance>
+ <duration>1908108</duration>
+ <syncTime>2008-06-27T12:27:37+00:00</syncTime>
+ <calories>380</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ <run id="7" workoutType="standard">
+ <startTime>2008-06-28T15:13:20-04:00</startTime>
+ <distance>3.7046</distance>
+ <duration>1772049</duration>
+ <syncTime>2008-07-01T11:38:07+00:00</syncTime>
+ <calories>365</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ <run id="8" workoutType="standard">
+ <startTime>2008-07-05T13:23:13-04:00</startTime>
+ <distance>4.2834</distance>
+ <duration>2143332</duration>
+ <syncTime>2008-07-06T21:48:08+00:00</syncTime>
+ <calories>422</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ <run id="9" workoutType="standard">
+ <startTime>2008-07-08T19:15:32-04:00</startTime>
+ <distance>3.8801</distance>
+ <duration>1831085</duration>
+ <syncTime>2008-07-10T22:42:30+00:00</syncTime>
+ <calories>382</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ <run id="10" workoutType="standard">
+ <startTime>2008-07-10T18:57:39-04:00</startTime>
+ <distance>4.5511</distance>
+ <duration>2136862</duration>
+ <syncTime>2008-07-10T23:39:39+00:00</syncTime>
+ <calories>440</calories>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ </run>
+ </runList>
+</plusService>
View
69 spec/xml/single_run_info.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plusService>
+ <status>success</status>
+ <sportsData>
+ <template>
+ <templateName><![CDATA[Basic]]></templateName>
+ </template>
+ <userInfo>
+ <weight>95.7</weight>
+ <device>iPod</device>
+ <empedID>ACVY12123ADS</empedID>
+ </userInfo>
+ <runSummary workoutType="standard">
+ <distance>4.1564</distance>
+ <duration>2558375</duration>
+ <calories>409</calories>
+ <equipmentType>ipod</equipmentType>
+ </runSummary>
+ <startTime>2008-05-17T16:27:33-04:00</startTime>
+ <snapShotList snapShotType="mileSplit">
+ <snapShot event="" id="1">
+ <distance>1.609</distance>
+ <duration>846097</duration>
+ <pace>658703</pace>
+ </snapShot>
+ <snapShot event="" id="2">
+ <distance>3.219</distance>
+ <duration>1730282</duration>
+ <pace>748180</pace>
+ </snapShot>
+ </snapShotList>
+ <snapShotList snapShotType="kmSplit">
+ <snapShot event="" id="3">
+ <distance>1.0</distance>
+ <duration>538492</duration>
+ <pace>376744</pace>
+ </snapShot>
+ <snapShot event="" id="4">
+ <distance>2.0</distance>
+ <duration>1026544</duration>
+ <pace>640617</pace>
+ </snapShot>
+ <snapShot event="" id="5">
+ <distance>3.0</distance>
+ <duration>1473808</duration>
+ <pace>689166</pace>
+ </snapShot>
+ <snapShot event="" id="6">
+ <distance>4.0</distance>
+ <duration>2347845</duration>
+ <pace>688212</pace>
+ </snapShot>
+ </snapShotList>
+ <snapShotList snapShotType="userClick">
+ <snapShot event="pause" id="7">
+ <distance>4.156</distance>
+ <duration>2558370</duration>
+ <pace>0</pace>
+ </snapShot>
+ </snapShotList>
+ <extendedDataList>
+ <extendedData dataType="" intervalType="time" intervalUnit="s" intervalValue="10">0.0,0.0091,0.0249,0.0386,0.056,0.0714,0.0856,0.1014,0.1181,0.1318,0.1469,0.1618,0.1777,0.1948,0.2096,0.2236,0.2396,0.2554,0.2716,0.2874,0.3034,0.3192,0.3357,0.3515,0.3646,0.3819,0.3977,0.4137,0.4271,0.4427,0.4593,0.4762,0.4889,0.5261,0.5552,0.5795,0.6086,0.6352,0.6617,0.6898,0.7168,0.7407,0.7574,0.7738,0.7904,0.8069,0.8248,0.8399,0.8544,0.8708,0.8924,0.92,0.948,0.9783,1.0055,1.0329,1.0578,1.0855,1.1103,1.1412,1.1675,1.1928,1.2189,1.2438,1.2681,1.2927,1.3152,1.3411,1.3612,1.3767,1.3901,1.405,1.4199,1.4349,1.4485,1.4631,1.4795,1.4944,1.5083,1.5236,1.5388,1.5529,1.5683,1.5843,1.6001,1.6155,1.6402,1.6699,1.6964,1.7244,1.7524,1.7783,1.8042,1.832,1.8596,1.8822,1.8966,1.9119,1.9276,1.9447,1.9586,1.9728,1.9888,2.0048,2.0318,2.0592,2.0868,2.1154,2.1419,2.1663,2.1958,2.219,2.246,2.2695,2.2957,2.3213,2.3461,2.3694,2.3945,2.4219,2.4454,2.4742,2.4972,2.5229,2.5464,2.5748,2.6024,2.6263,2.6507,2.6661,2.6798,2.6961,2.7095,2.7241,2.7386,2.7518,2.7664,2.7836,2.7962,2.8099,2.8378,2.8626,2.8907,2.9186,2.9433,2.9642,2.9797,2.996,3.0095,3.0248,3.0404,3.0552,3.0683,3.0829,3.0947,3.1057,3.1057,3.1084,3.1138,3.1138,3.1138,3.1138,3.1138,3.1138,3.1138,3.1138,3.1157,3.1333,3.1461,3.1603,3.1747,3.1905,3.2058,3.2193,3.2325,3.2488,3.2627,3.2774,3.2934,3.3073,3.3215,3.3269,3.3269,3.3269,3.3269,3.3389,3.3545,3.3689,3.3773,3.3968,3.4114,3.4258,3.4395,3.4523,3.4665,3.4809,3.4951,3.5093,3.5237,3.5364,3.5508,3.5657,3.5787,3.5927,3.6082,3.6236,3.6387,3.6535,3.6688,3.6835,3.6953,3.6953,3.6953,3.6997,3.7125,3.7272,3.7427,3.756,3.766,3.7797,3.7945,3.8048,3.818,3.832,3.8471,3.8613,3.8743,3.8903,3.9038,3.9186,3.9333,3.9477,3.9614,3.9744,3.9883,4.0032,4.0162,4.0303,4.046,4.0599,4.0703,4.0826,4.097,4.1058,4.1118,4.125,4.1356,4.1395,4.1434,4.1434,4.1484,4.1484,4.1484,4.1524,4.1564,4.1564</extendedData>
+ </extendedDataList>
+ <bestComparableRun>3</bestComparableRun>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ <signatureValidationStatus>1</signatureValidationStatus>
+ </sportsData>
+</plusService>

0 comments on commit b293d90

Please sign in to comment.