Skip to content

Instantly share code, notes, and snippets.

@robotarmy
Created March 23, 2012 23:55
Show Gist options
  • Save robotarmy/2176510 to your computer and use it in GitHub Desktop.
Save robotarmy/2176510 to your computer and use it in GitHub Desktop.

Revisions

  1. robotarmy revised this gist Mar 23, 2012. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Instructions.creole
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    == Installing Rspec into Sinatra with Rake
    === in your project directory



    #Open the Gist [[https://gist.github.com/2176510| GIST with complete instructions and files]]
    #Update the Gemfile
    #Update the Rakefile
    #Create a .rspec file
  2. @invalid-email-address Anonymous revised this gist Mar 23, 2012. 1 changed file with 11 additions and 14 deletions.
    25 changes: 11 additions & 14 deletions Instructions.creole
    Original file line number Diff line number Diff line change
    @@ -1,35 +1,32 @@
    <h1> Installing Rspec into Sinatra with Rake </h1>
    <h5>in your project directory</h5>
    == Installing Rspec into Sinatra with Rake
    === in your project directory

    #Update the Gemfile
    #Update the Rakefile
    #Create a .rspec file
    #Follow the Instructions

    <h2>Instructions</h2>
    <code>
    ====Instructions
    {{{
    # 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>
    }}}
  3. @invalid-email-address Anonymous renamed this gist Mar 23, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @invalid-email-address Anonymous created this gist Mar 23, 2012.
    5 changes: 5 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    gem 'sinatra'
    group :development,:test do
    gem 'rspec'
    gem 'rack-test'
    end
    35 changes: 35 additions & 0 deletions Instructions.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    <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>
    7 changes: 7 additions & 0 deletions Rakefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    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)
    12 changes: 12 additions & 0 deletions instance_variable_spec.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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
    32 changes: 32 additions & 0 deletions spec_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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