Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated README.md

  • Loading branch information...
commit db278563b207345c4ded1973bae51c3ee0c77977 1 parent 049e4ea
authored February 13, 2013

Showing 1 changed file with 67 additions and 1 deletion. Show diff stats Hide diff stats

  1. 68  README.md
68  README.md
Source Rendered
@@ -316,6 +316,8 @@ When having the following situation:
316 316
       puts HTTParty.get("https://github.com/archan937/lock-o-motion").parsed_response
317 317
     end
318 318
 
  319
+#### Without mocking
  320
+
319 321
 As opposed to having the `HTTParty` mock to our availability. The console output would look like this:
320 322
 
321 323
     1.9.3 paulengel:just_awesome $ rake
@@ -341,7 +343,9 @@ As opposed to having the `HTTParty` mock to our availability. The console output
341 343
     (main)> 2013-02-13 01:21:39.888 Just Awesome[59028:c07] lotion.rb:17:in `require:': cannot load such file -- pathname.so (LoadError)
342 344
       from core_ext.rb:39:in `require:'
343 345
 
344  
-When we do have the `HTTParty` mock to our availability, we can just leave the code as is and get a console output like this:
  346
+#### With mocking
  347
+
  348
+When we do have the `HTTParty` mock available, we can just leave the code as is and get a console output like this:
345 349
 
346 350
     1.9.3 paulengel:just_awesome $ rake
347 351
          Build ./build/iPhoneSimulator-6.1-Development
@@ -370,6 +374,68 @@ When we do have the `HTTParty` mock to our availability, we can just leave the c
370 374
         <meta name="msapplication-TileImage"
371 375
     (main)>
372 376
 
  377
+#### So what's the point?
  378
+
  379
+Maybe you are thinking why someone would do something like this. Well, after having mocked `HTTParty`, I now am able to use the [betty_resource](https://github.com/bettyblocks/betty_resource/tree/edge) gem for instance. At first, I could not use the `betty_resource` gem because it has `HTTParty` as gem dependency but since that problem is eliminated, I can.
  380
+
  381
+As an example:
  382
+
  383
+**Gemfile**
  384
+
  385
+    source "http://rubygems.org"
  386
+
  387
+    # RubyMotion aware gems
  388
+    gem "lock-o-motion"
  389
+
  390
+    # RubyMotion unaware gems
  391
+    group :lotion do
  392
+      gem "betty_resource", :path => "/Users/paulengel/Sources/betty_resource"
  393
+    end
  394
+
  395
+**Fragment of a defined UIViewController for instance**
  396
+
  397
+    def viewDidLoad
  398
+      super
  399
+      puts HTTParty.get("https://github.com/archan937/lock-o-motion").parsed_response[0, 1000]
  400
+      puts BettyResource::Api.get("/models/2c449a396a6a46159cd5f256622fd75f/records/1").parsed_response
  401
+      puts BettyResource::Relation.get(1).inspect
  402
+      puts BettyResource::Relation.get(1).first_name
  403
+    end
  404
+
  405
+When running the application:
  406
+
  407
+    1.9.3 paulengel:just_awesome $ rake
  408
+         Build ./build/iPhoneSimulator-6.1-Development
  409
+       Compile /Users/paulengel/Sources/just_awesome/.lotion.rb
  410
+          Link ./build/iPhoneSimulator-6.1-Development/Just Awesome.app/Just Awesome
  411
+        Create ./build/iPhoneSimulator-6.1-Development/Just Awesome.dSYM
  412
+      Simulate ./build/iPhoneSimulator-6.1-Development/Just Awesome.app
  413
+    (main)>
  414
+
  415
+
  416
+    <!DOCTYPE html>
  417
+    <html>
  418
+      <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# githubog: http://ogp.me/ns/fb/githubog#">
  419
+        <meta charset='utf-8'>
  420
+        <meta http-equiv="X-UA-Compatible" content="IE=edge">
  421
+            <title>archan937/lock-o-motion · GitHub</title>
  422
+        <link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub" />
  423
+        <link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub" />
  424
+        <link rel="apple-touch-icon-precomposed" sizes="57x57" href="apple-touch-icon-114.png" />
  425
+        <link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114.png" />
  426
+        <link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-144.png" />
  427
+        <link rel="apple-touch-icon-precomposed" sizes="144x144" href="apple-touch-icon-144.png" />
  428
+        <link rel="logo" type="image/svg" href="http://github-media-downloads.s3.amazonaws.com/github-logo.svg" />
  429
+        <meta name="msapplication-TileImage"
  430
+    {"last_name"=>"Willemse", "first_name"=>"Daniel", "id"=>1}
  431
+    #<BettyResource::Relation @id=1 @last_name=<not loaded> @first_name=<not loaded>>
  432
+    Daniel
  433
+    (main)>
  434
+
  435
+When you are only using gems which are maintained by yourself, you would not have to mock its dependencies of course. But you do when dealing with third party gems.
  436
+
  437
+#### Creating mocks
  438
+
373 439
 I am planning on writing more "mocks" for common Ruby gems. But aside from mocks being defined within the LockOMotion gem sources, you can also define your own mocks within your RubyMotion application. Just add a directory called `mocks` within the root directory of the application and put the "mock sources" in it. The relative path of the mock source within that directory ensures a certain Ruby gem being mocked at compile time.
374 440
 
375 441
 Let's say the root directory of your RubyMotion application is `/Users/paulengel/Sources/just_awesome`. If you want to mock `require "httparty"`, create a file at `/Users/paulengel/Sources/just_awesome/mocks/httparty.rb` containing the mock code. If you want to mock `require "net/http"`, create a file at `/Users/paulengel/Sources/just_awesome/mocks/net/http.rb`. Cool, huh?

0 notes on commit db27856

Please sign in to comment.
Something went wrong with that request. Please try again.