Created
March 23, 2012 23:55
-
-
Save robotarmy/2176510 to your computer and use it in GitHub Desktop.
Adding Rake to Sinatra with Rspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gem 'sinatra' | |
| group :development,:test do | |
| gem 'rspec' | |
| gem 'rack-test' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe "My Site" do | |
| def app | |
| app_instance = MySite.prepare_instance | |
| end | |
| context "before" do | |
| it "sets @title" do | |
| get "/" | |
| app.instance_variable_get("@title").should match("Thanks to the person that figured out how to get the Sinatra app instance") | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h1> Installing Rspec into Sinatra with Rake </h1> | |
| <h5>in your project directory</h5> | |
| #Update the Gemfile | |
| #Update the Rakefile | |
| #Create a .rspec file | |
| #Follow the Instructions | |
| <h2>Instructions</h2> | |
| <code> | |
| # run the bundle command | |
| $ bundle | |
| </code> | |
| <code> | |
| # .rspec file | |
| $ echo "--color" >> .rspec | |
| $ echo "--backtrace" >> .rspec | |
| </code> | |
| <code> | |
| # .rspec file | |
| $ echo "--color" >> .rspec | |
| $ echo "--backtrace" >> .rspec | |
| </code> | |
| <code> | |
| # spec directory | |
| $ mkdir spec | |
| $ touch spec/spec_helper.rb | |
| # Update spec/spec_helper.rb to match file in gist. | |
| # mkdir spec/sample | |
| $ touch spec/sample/instance_variable_spec.rb | |
| # update spec/sample/instance_variable_spec.rb to match file in gist | |
| </code> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rspec/core' | |
| require 'rspec/core/rake_task' | |
| task :default => :spec | |
| desc "Run all specs in spec directory (excluding plugin specs)" | |
| RSpec::Core::RakeTask.new(:spec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rack/test' | |
| # Require your modules here | |
| # this is how i do it: | |
| # require_relative '../sinatra_modules' | |
| RSpec.configure do |conf| | |
| conf.include Rack::Test::Methods | |
| end | |
| #https://gist.github.com/1523353 | |
| class Sinatra::Base | |
| @@prepared = nil | |
| def self.onion_core | |
| onion = prototype | |
| loop do | |
| onion = onion.instance_variable_get('@app') | |
| return onion if onion.class == self || onion.nil? | |
| end | |
| end | |
| def self.prepare_instance | |
| @@prepared = onion_core | |
| end | |
| # Override | |
| def call(env) | |
| d = @@prepared || dup | |
| @@prepared = nil | |
| d.call!(env) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment