Skip to content

Instantly share code, notes, and snippets.

@jodosha
Last active January 4, 2016 08:19
Show Gist options
  • Save jodosha/8594998 to your computer and use it in GitHub Desktop.
Save jodosha/8594998 to your computer and use it in GitHub Desktop.
Example of Lotus::Router usage. It includes integration and unit tests examples. Clone this gist and then run `bash setup.sh` to run the app: `rackup application.rb`.
require 'lotus/router'
Application = Rack::Builder.new do
router = Lotus::Router.new do
get '/', to: ->(env) { [200, {}, ['Hello World']] }, as: :root
end
run router
end.to_app
source 'https://rubygems.org'
gem 'lotus-router'
group :test do
gem 'rspec'
gem 'capybara'
end
# spec/features/home_page_spec.rb
require 'spec_helper'
feature 'Home page' do
it 'successfully visits the home page' do
visit '/'
expect(page.body).to match('Hello World')
end
end
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task default: :spec
# spec/routing_spec.rb
require 'spec_helper'
describe Application do
let(:application) { Application }
it 'recognizes route path' do
expect(application.path(:root)).to eq('/')
end
end
#!/bin/bash
mkdir -p spec/features
mv spec_helper.rb spec
mv routing_spec.rb spec
mv home_page_spec.rb spec/features
bundle
# This script will self destruct in 3, 2, 1.. poof!
rm -- "$0"
# spec/spec_helper.rb
$:.unshift __dir__ + '/..'
require 'rubygems'
require 'bundler'
Bundler.require(:default, :test)
require 'rspec'
require 'capybara/rspec'
require 'application'
module RSpec
module FeatureExampleGroup
def self.included(group)
group.metadata[:type] = :feature
Capybara.app = Application
end
end
end
RSpec.configure do |c|
def c.escaped_path(*parts)
Regexp.compile(parts.join('[\\\/]') + '[\\\/]')
end
c.color = true
c.include RSpec::FeatureExampleGroup, type: :feature, example_group: {
file_path: c.escaped_path(%w[spec features])
}
c.include Capybara::DSL, type: :feature
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment