Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SwiftでHTTP通信のスタブ化 / Stubbing HTTP Requests in Swift

03c0e11ea6f2a3e08b3c46db5877c8e1?s=47 Jiro Nagashima
February 28, 2015

SwiftでHTTP通信のスタブ化 / Stubbing HTTP Requests in Swift

#33testing

03c0e11ea6f2a3e08b3c46db5877c8e1?s=128

Jiro Nagashima

February 28, 2015
Tweet

More Decks by Jiro Nagashima

Other Decks in Technology

Transcript

  1. 4XJGU Ͱ )551௨৴ͷελϒԽ !IFEKJSPH

  2. ͳ͕͠·͡Ζ͏ !IFEKJSPH 4BOTBOגࣜձࣾ&JHIU

  3. )551௨৴ͷελϒԽ

  4. /-5)5514UVC4FSWFS ैདྷख๏ 0))5514UVCT FUD…

  5. ΞϓϦ಺෦ͷαʔόʔ ैདྷख๏ /463-1SPUPDPMʹ४ڌͨ͠Ϋϥε .FUIPE4XJ[[MJOH

  6. ʷΞϓϦ಺෦ͷαʔόʔ ैདྷख๏ ʷ/463-1SPUPDPMʹ४ڌͨ͠Ϋϥε ʷ.FUIPE4XJ[[MJOH

  7. .PZB

  8. None
  9. None
  10. .PZB w ωοτϫʔΫपΓͷந৅ԽϨΠϠʔ w ςετ༻ͷελϒ΋ѻ͑Δ

  11. Πϝʔδ͸͜Μͳײ͡ IUUQEFWFMPQFSIBUFOBTUBGGDPNFOUSZTNBSUBQJDMJFOUXJUITXJGU VTJOHFOVNBOEHFOFSJDT

  12. IFEKJSPH2JJUB'FFE

  13. "1*ͷهड़

  14. enum QiitaAPI { case Items case TagItems(String) } FOVNఆٛ

  15. extension QiitaAPI : MoyaPath { var path: String { switch

    self { case .Items: return "/api/v2/items" case .TagItems(let tagID): return "/api/v2/tags/\(tagID)/items" } } } ύεࢦఆ
  16. extension QiitaAPI : MoyaTarget { var baseURL: NSURL { return

    NSURL(string: "https://qiita.com")! } var sampleData: NSData { switch self { case .Items, .TagItems: return stubbedResponse("Items") } } } B63-ࢦఆ
  17. extension QiitaAPI : MoyaTarget { var baseURL: NSURL { return

    NSURL(string: "https://qiita.com")! } var sampleData: NSData { switch self { case .Items, .TagItems: return stubbedResponse("Items") } } } CελϒԽͨ͠ϨεϙϯεΛࢦఆ
  18. ϓϩόΠμͷ੾Γସ͑

  19. static func DefaultProvider() -> ReactiveMoyaProvider<QiitaAPI> { return ReactiveMoyaProvider(endpointsClosure: endpointsClosure) }

    static func StubbingProvider() -> ReactiveMoyaProvider<QiitaAPI> { return ReactiveMoyaProvider(endpointsClosure: endpointsClosure, stubResponses: true) } ϓϩόΠμఆٛ
  20. QiitaProvider.sharedProvider = QiitaProvider.StubbingProvider() ੾Γସ͑

  21. IUUQTHJUIVCDPNBSUTZFJEPMPO ࢀߟ IUUQTHJUIVCDPN"TI'VSSPX.PZB σϞ IUUQTHJUIVCDPNIFEKJSPH2JJUB'FFE