Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Commit

Permalink
configuration, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sosedoff committed Jul 1, 2011
1 parent e484ac0 commit 71afddf
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .rspec
@@ -0,0 +1,2 @@
--color
--format=nested
13 changes: 13 additions & 0 deletions Rakefile
@@ -0,0 +1,13 @@
require 'bundler'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:test) do |t|
t.pattern = 'spec/*_spec.rb'
t.verbose = false
end

task :default => :test

task :environment do
require './app'
end
21 changes: 15 additions & 6 deletions app.rb
Expand Up @@ -2,12 +2,18 @@
require 'docify'
require 'sinatra'

VERSION = '0.1.0'
VERSION = '0.1.1'

configure do
set :views, 'app/views'
end

configure :production do
set :show_exceptions, false
set :dump_errors, false
set :raise_errors, false
end

helpers do
def app_version
VERSION
Expand All @@ -19,9 +25,12 @@ def app_version
end

post '/render' do
begin
Docify.render(params[:content], params[:markup])
rescue Exception => ex
"Request failder: #{ex.inspect}"
end
content = params[:content].to_s
markup = params[:markup].to_s

halt 400, "Content required" if content.empty?
halt 400, "Markup required" if markup.empty?
halt 400, "Invalid markup" if !Docify.valid_format?(params[:markup])

Docify.render(params[:content], params[:markup])
end
29 changes: 29 additions & 0 deletions spec/app_spec.rb
@@ -0,0 +1,29 @@
require 'spec_helper'

describe 'Application' do
it 'should respond to /' do
get '/'
last_response.status.should == 200
end

it 'should render the content on /render' do
post '/render'

last_response.status.should == 400
last_response.body.should match(/Content required/)

post '/render', :content => "Hello world"
last_response.status.should == 400
last_response.body.should match(/Markup required/)

post '/render', :content => "Hello world", :markup => 'invalidmarkup'
last_response.status.should == 400
last_response.body.should match(/Invalid markup/)

%w(markdown textile rdoc).each do |m|
post '/render', :content => "Hello world", :markup => m
last_response.status.should == 200
last_response.body.should match(/Hello world/)
end
end
end
36 changes: 36 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,36 @@
$:.unshift File.expand_path("../..", __FILE__)

require 'app'
require 'webmock'
require 'webmock/rspec'
require 'rack/test'

set :environment, :test

RSpec.configure do |conf|
conf.include Rack::Test::Methods
end

def app
Sinatra::Application
end

def fixture_path
File.expand_path("../fixtures", __FILE__)
end

def fixture(file)
File.read(File.join(fixture_path, file))
end

def basecamp(opts={})
Services::Basecamp.new(opts)
end

def campfire(opts={})
Services::Campfire.new(opts)
end

def postbin(opts={})
Services::Postbin.new(opts)
end

0 comments on commit 71afddf

Please sign in to comment.