Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: michaelparenteau/michaelparenteau
base: 7b1640857c
...
head fork: michaelparenteau/michaelparenteau
compare: 30bb422445
  • 7 commits
  • 8 files changed
  • 0 commit comments
  • 2 contributors
Commits on Nov 27, 2011
@rsanheim rsanheim getting specs wired up 73d54e4
@rsanheim rsanheim using rspec and stuff 66d425b
@rsanheim rsanheim document the specs e134470
@rsanheim rsanheim Bring back the tweets...
  - using ActiveSupport Cache (in memory only) to store last tweets
  - last tweet will be stored for four hours by default
  - bring in guard to speed up dev with fast spec runs
  - show the time out message for tweets only if there wasn't a tweet
    found
80ed7ae
@rsanheim rsanheim make sure we don't die if Twitter blows up ac6e784
@rsanheim rsanheim document guard 268243d
Commits on Dec 06, 2011
@michaelparenteau Merge pull request #1 from michaelparenteau/hey-buddy
Bringing back the tweets - Thanks Rob!
30bb422
View
14 Gemfile
@@ -1,4 +1,7 @@
source "http://rubygems.org"
+gem "i18n"
+gem "activesupport", "~> 3.1", :require => nil
+gem "rake"
gem "rack"
gem "sinatra", "1.1.2", :require => "sinatra"
gem "haml"
@@ -6,4 +9,13 @@ gem "sinatra-static-assets"
gem "maruku"
gem "swish"
gem "twitter"
-gem "heroku"
+gem "heroku"
+
+group :test do
+ gem "fakeweb"
+ gem "rack-test"
+ gem "mocha"
+ gem "rspec"
+ gem "guard"
+ gem "guard-rspec"
+end
View
33 Gemfile.lock
@@ -1,16 +1,24 @@
GEM
remote: http://rubygems.org/
specs:
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
addressable (2.2.6)
crack (0.3.1)
+ diff-lcs (1.1.3)
emk-sinatra-url-for (0.2.1)
sinatra (>= 0.9.1.1)
+ fakeweb (1.3.0)
faraday (0.7.5)
addressable (~> 2.2.6)
multipart-post (~> 1.1.3)
rack (>= 1.1.0, < 2)
faraday_middleware (0.7.0)
faraday (~> 0.7.3)
+ guard (0.8.8)
+ thor (~> 0.14.6)
+ guard-rspec (0.5.7)
+ guard (>= 0.8.4)
haml (3.0.25)
hashie (1.1.0)
heroku (2.11.0)
@@ -21,17 +29,32 @@ GEM
httparty (0.8.1)
multi_json
multi_xml
+ i18n (0.6.0)
launchy (2.0.5)
addressable (~> 2.2.6)
maruku (0.6.0)
syntax (>= 1.0.0)
+ metaclass (0.0.1)
mime-types (1.17.2)
+ mocha (0.10.0)
+ metaclass (~> 0.0.1)
multi_json (1.0.3)
multi_xml (0.4.1)
multipart-post (1.1.3)
rack (1.2.1)
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rake (0.9.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
rubyzip (0.9.4)
simple_oauth (0.1.5)
sinatra (1.1.2)
@@ -46,6 +69,7 @@ GEM
httparty (>= 0.6.1)
syntax (1.0.0)
term-ansicolor (1.0.7)
+ thor (0.14.6)
tilt (1.2.2)
twitter (1.7.2)
faraday (~> 0.7.4)
@@ -59,10 +83,19 @@ PLATFORMS
ruby
DEPENDENCIES
+ activesupport (~> 3.1)
+ fakeweb
+ guard
+ guard-rspec
haml
heroku
+ i18n
maruku
+ mocha
rack
+ rack-test
+ rake
+ rspec
sinatra (= 1.1.2)
sinatra-static-assets
swish
View
13 Guardfile
@@ -0,0 +1,13 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch('spec/spec_helper.rb') { "spec" }
+ watch('app.rb') { "spec" }
+ watch(%r{^(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
+
View
10 README.md
@@ -4,6 +4,16 @@
This is my playground. I will have a place to show my artwork, some of my user interface design and I will also start making some poster-like blog posts. I had a lot of fun making all of this so far and plan on continuing the theme. All art, design and development was done by me. You can see it all here, even the PSD. Enjoy
+## Running Specs
+
+Simple spec suite using RSpec/Mocha can be run via:
+
+ rake # the default task runs the whole suite
+
+Or for automatic test runs while developing:
+
+ bundle exec guard
+
## Tech Used:
* [Sinatra](http://sinatrarb.com) (Ruby and Rubygems)
View
8 Rakefile
@@ -0,0 +1,8 @@
+require "rubygems"
+require "bundler/setup"
+require "rspec/core/rake_task"
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => [:spec]
+
View
38 app.rb
@@ -2,25 +2,35 @@
require "bundler/setup"
require "rack"
require "sinatra"
-require 'sinatra/static_assets'
-require 'swish'
-require 'twitter'
+require "sinatra/static_assets"
+require "swish"
+require "twitter"
+require "active_support/cache"
-
-# FOR BASIC AUTH USE BELOW, REPLACE ['username', 'password'] with actual credentials
-# use Rack::Auth::Basic do |username, password|
-# [username, password] == ['username', 'password']
-# end
+DefaultCacheExpirationTime = 4.hours
set :haml, {:format => :html5}
+set :cache, ActiveSupport::Cache::MemoryStore.new(:expires_in => DefaultCacheExpirationTime)
get '/' do
-
@page_title = "Artist & Designer at Relevance, Inc. in Durham, NC"
- # @tweet = Twitter.user_timeline("parenteau").first.text
- @player = Dribbble::Player.find('michaelparenteau')
- @shot = @player.shots.first
-
+ @tweet = last_tweet
+ @shot = last_shot
haml :index
+end
+
+def last_shot
+ Dribbble::Player.find('michaelparenteau').shots.first
+end
-end
+def last_tweet
+ settings.cache.fetch(:last_tweet) do
+ begin
+ Twitter.user_timeline("parenteau").first.text
+ rescue => e
+ $stderr.puts "Could not retrieve latest tweet!"
+ $stderr.puts e
+ nil
+ end
+ end
+end
View
52 spec/app_spec.rb
@@ -0,0 +1,52 @@
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[..])
+Bundler.require(:test)
+ENV['RACK_ENV'] = 'test'
+require 'app'
+require 'rspec'
+require 'mocha'
+require 'rack/test'
+
+RSpec.configure do |conf|
+ conf.include Rack::Test::Methods
+ conf.mock_with :mocha
+end
+
+describe "the App" do
+ def app
+ Sinatra::Application
+ end
+
+ before do
+ # Don't allow any real http requests -- we don't want Dribble or Twitter
+ # requests happening during test runs
+ FakeWeb.allow_net_connect = false
+ end
+
+ it "has a good response" do
+ app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
+ app.any_instance.stubs(:last_tweet).returns("some tweet")
+ get '/'
+ last_response.should be_ok
+ end
+
+ it "shows friendly error message if tweets can't be loaded" do
+ app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
+ app.any_instance.expects(:last_tweet).returns(nil)
+ get "/"
+ last_response.body.should include("Twitter requests are timing out")
+ end
+
+ it "shows friendly error message if twitter raises an exception" do
+ app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
+ Twitter.expects(:user_timeline).raises(RuntimeError)
+ get "/"
+ last_response.body.should include("Twitter requests are timing out")
+ end
+
+ it "shows the latest tweet" do
+ app.any_instance.stubs(:last_shot).returns(stub_everything("dribble shot"))
+ app.any_instance.expects(:last_tweet).returns("this is a tweet!")
+ get "/"
+ last_response.body.should include("this is a tweet!")
+ end
+end
View
8 views/index.haml
@@ -13,8 +13,10 @@
%a{:href => 'http://twitter.com/michaelparenteau',:target => '_blank'} twitter
.tweet
%p
- Twitter requests are timing out... sorry, this is not the tweet you are looking for.
- / = @tweet
+ -if @tweet.nil?
+ Twitter requests are timing out... sorry, this is not the tweet you are looking for.
+ -else
+ = @tweet
.four.columns.ampersand
=image_tag("/images/ampersand.png", :alt => "Ampersand (&)")
.six.columns.dribbble
@@ -25,4 +27,4 @@
.clear
.sixteen.columns.surfer-and-fish-water
- =image_tag("/images/surfer-and-fish-water.png", :alt => "Cyclops alien on a surfboard chasing 3 flying fish")
+ =image_tag("/images/surfer-and-fish-water.png", :alt => "Cyclops alien on a surfboard chasing 3 flying fish")

No commit comments for this range

Something went wrong with that request. Please try again.