Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created April 15, 2012 19:18
Show Gist options
  • Save ngauthier/2394387 to your computer and use it in GitHub Desktop.
Save ngauthier/2394387 to your computer and use it in GitHub Desktop.
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp

SinatraGemSpec

Example of using bundler for path management.

Bootstrap

bundle gem sinatra_gem_spec

Use bundler to make a gem scaffold

Gemfile

source 'https://rubygems.org'
gemspec

group :development, :test do
  gem 'sinatra_gem_spec', :path => '.'
end

Specify the library as a gem in the current path for dev and test. When you run bundle it will recognize the gem.

config.ru

require 'rubygems'
require 'bundler/setup'
require 'sinatra_gem_spec'
run SinatraGemSpec::Server

Use bunder to load your app and then run it.

spec_helper.rb

require 'rubygems'
require 'bundler/setup'
require 'capybara/rspec'
require 'sinatra_gem_spec'
Capybara.app = SinatraGemSpec::Server

Again, use bundler to load, then give capybara the server.

sinatra_gem_spec.rb

require "sinatra_gem_spec/version"
module SinatraGemSpec
  autoload :Server, 'sinatra_gem_spec/server'
end

Server will be the sinatra app. Autoload for speed when loading environment.

sinatra_gem_spec/server.rb

require 'sinatra'
class SinatraGemSpec::Server < Sinatra::Base
  get '/' do
    'hello world'
  end
end

Basic sinatra app

spec/hello_world_spec.rb

require 'spec_helper'
describe SinatraGemSpec::Server, :type => :request do
  it 'should say hello' do
    visit '/'
    page.should have_content('hello world')
  end
end

Basic request spec.

Easy!

require 'rubygems'
require 'bundler/setup'
require 'sinatra_gem_spec'
run SinatraGemSpec::Server
source 'https://rubygems.org'
gemspec
group :development, :test do
gem 'sinatra_gem_spec', :path => '.'
end
require 'spec_helper'
describe SinatraGemSpec::Server, :type => :request do
it 'should say hello' do
visit '/'
page.should have_content('hello world')
end
end
Copyright (c) 2012 Nick Gauthier
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'sinatra'
class SinatraGemSpec::Server < Sinatra::Base
get '/' do
'hello world'
end
end
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/sinatra_gem_spec/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Nick Gauthier"]
gem.email = ["ngauthier@gmail.com"]
gem.description = %q{Example of bundler-based project development}
gem.summary = %q{Example of bundler-based project development}
gem.homepage = ""
gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "sinatra_gem_spec"
gem.require_paths = ["lib"]
gem.version = SinatraGemSpec::VERSION
gem.add_dependency 'sinatra'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'capybara'
end
require "sinatra_gem_spec/version"
module SinatraGemSpec
autoload :Server, 'sinatra_gem_spec/server'
end
require 'rubygems'
require 'bundler/setup'
require 'capybara/rspec'
require 'sinatra_gem_spec'
Capybara.app = SinatraGemSpec::Server
module SinatraGemSpec
VERSION = "0.0.1"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment