Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added some example specs.

  • Loading branch information...
commit f6c2ae438a6e2ea69aff230f0738f55e58ce89ad 1 parent 1ba6c92
@clarkware clarkware authored
View
8 episode-020/Magic8Ball/README.md
@@ -1,11 +1,17 @@
# Magic Eight Ball: A RubyMotion Example App
+## Screencast
+
+To watch this app being built incrementally, check out the
+[free 50-minute screencast](http://pragmaticstudio.com/screencasts/rubymotion).
+
## Quick Start
1. Install [Xcode](http://itunes.apple.com/us/app/xcode/id497799835?mt=12)
2. Install [RubyMotion](http://www.rubymotion.com/)
3. Run `rake` to build the project and run the app in the Simulator
-4. Run `rake device` to build the project and run the app on a provisioned iOS device
+4. Run `rake spec` to run all the specs
+5. Run `rake device` to build the project and run the app on a provisioned iOS device
## Credits
View
1  episode-020/Magic8Ball/app/magic_8ball.rb
@@ -1,4 +1,5 @@
class Magic8Ball
+ attr_reader :answers
def initialize
@answers = loadAnswers
View
1  episode-020/Magic8Ball/app/magic_8ball_view_controller.rb
@@ -1,4 +1,5 @@
class Magic8BallViewController < UIViewController
+ attr_reader :label
def loadView
self.view = UIImageView.alloc.init
View
15 episode-020/Magic8Ball/spec/magic_8ball_spec.rb
@@ -0,0 +1,15 @@
+describe "Magic8Ball" do
+ before do
+ @eightBall = Magic8Ball.new
+ end
+
+ it "has 13 answers" do
+ @eightBall.answers.size.should.equal 13
+ end
+
+ it "generates a random answer" do
+ answer = @eightBall.randomAnswer
+
+ @eightBall.answers.should.include answer
+ end
+end
View
35 episode-020/Magic8Ball/spec/magic_8ball_view_controller_spec.rb
@@ -0,0 +1,35 @@
+describe "Magic8BallViewController" do
+ before do
+ @vc = Magic8BallViewController.alloc.init
+ @vc.view # force the view to load
+ end
+
+ it "has a background image" do
+ @vc.view.image.should.not.be.nil
+ end
+
+ it "has a label" do
+ @vc.label.text.should == "Tap For Answer!"
+ end
+
+ it "has a single-tap gesture recognizer" do
+ @vc.view.gestureRecognizers.size.should.equal 1
+
+ tap = @vc.view.gestureRecognizers.first
+ tap.numberOfTapsRequired.should.equal 1
+ end
+
+ it "updates the label when the answer is shown" do
+ class Magic8Ball
+ def randomAnswer
+ "No So Random"
+ end
+ end
+
+ @vc.showAnswer
+
+ wait 1.0 do
+ @vc.label.text.should == "No So Random"
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.