Created
December 29, 2011 07:49
-
-
Save we4tech/1532760 to your computer and use it in GitHub Desktop.
Sinatra with Rspec and custom rspec matcher
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
RSpec::Matchers.define :be_huka do | |
match do |actual| | |
actual == true | |
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
require 'rubygems' | |
require 'bundler' | |
Bundler.require | |
require './hello_app' | |
run HelloApp::Routes |
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
source 'http://rubygems.org' | |
gem 'sinatra' | |
group :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
module HelloApp | |
module Models | |
class TestModel | |
attr_accessor :name, :email | |
def save | |
true | |
end | |
end | |
end | |
class Routes < Sinatra::Base | |
get '/' do | |
'Hello world' | |
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
require File.join(File.dirname(__FILE__), '..', 'spec_helper') | |
describe HelloApp::Models::TestModel do | |
describe '#save' do | |
let(:test_model) { HelloApp::Models::TestModel.new } | |
subject { test_model } | |
its(:save) { should be_huka } | |
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
require 'rubygems' | |
require 'bundler' | |
Bundler.require | |
require File.join(File.dirname(__FILE__), '..', 'hello_app') | |
require 'rspec' | |
require 'rspec/autorun' | |
# set test environment | |
set :environment, :test | |
set :run, false | |
set :raise_errors, true | |
set :logging, false | |
# Define new matcher | |
RSpec::Matchers.define :be_huka do | |
match do |actual| | |
actual == true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment