Created
December 9, 2012 05:21
-
-
Save royw/4243452 to your computer and use it in GitHub Desktop.
Issue where provide json handling is being invoked on rspec+capybara visit on Ramaze 2012.12.08
This file contains 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 'spec_helper' | |
# abridged | |
feature "Home Page" do | |
background do | |
@session.header 'Accept', 'text/html' | |
end | |
scenario 'Accessing the home page' do | |
visit('/') | |
within('#top') do | |
find_link('Help').visible? | |
find_link('Home').visible? | |
find_link('Login').visible? | |
end | |
end | |
end |
This file contains 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
# abridged, just the provide json handler | |
Class MyController < Controller | |
helper :flash | |
# expects value to behave like a Hash | |
provide(:json, :type => 'application/json') do |action, value| | |
# "value" is the response body from our controller's method | |
value.rewind if value.respond_to?('rewind') | |
error_hash = {:error => Ramaze::Current.session.flash[:error], | |
:error_backtrace => Ramaze::Current.session.flash[:error_backtrace]} | |
Ramaze::Log.info "value => #{value.inspect}" | |
(value.merge(error_hash)).delete_if{|k,v| v.nil?}.to_json | |
end | |
end | |
module Innate | |
module Node | |
# Resolve possible provides for the given +path+. | |
# | |
# @param [String] path | |
# | |
# @return [Array] with name, wish, engine | |
# | |
# @api internal | |
# @see Node::provide Node::provides | |
# @author manveru | |
def find_provide(path) | |
pr = provides | |
name, wish, engine = path, 'html', pr['html_handler'] | |
accept = request.env['rack-accept.request'] | |
Ramaze::Log.info "accept=>#{accept.pretty_inspect}" | |
unless accept.nil? | |
http_accept = accept.env['HTTP_ACCEPT'] || 'text/html' | |
Ramaze::Log.info "http_accept=>#{http_accept.pretty_inspect}" | |
unless http_accept.nil? | |
types = http_accept.strip.split(/[, ]+/) | |
Ramaze::Log.info "types=>#{types.pretty_inspect}" | |
unless types.empty? | |
content_types = ancestral_trait.reject{|key, value| key !~ /_content_type$/ } | |
matching_types = content_types.select{|key, value| types.include? value} | |
matching_types.each do |key, value| | |
prefix = $1 if key =~ /^(.*)_content_type$/ | |
handler = pr["#{prefix}_handler"] | |
unless handler.nil? | |
name, wish, engine = path, prefix, handler | |
break | |
end | |
end | |
end | |
end | |
end | |
pr.find do |key, value| | |
key = key[/(.*)_handler$/, 1] | |
next unless path =~ /^(.+)\.#{key}$/i | |
name, wish, engine = $1, key, value | |
end | |
Ramaze::Log.info "name=>#{name}, wish=>#{wish}, engine=>#{engine}" | |
return name, wish, engine | |
end | |
end | |
end |
This file contains 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 'simplecov' | |
require 'simplecov-rcov' | |
def coverage_directory | |
dir = File.expand_path('doc/coverage', '/Users/roy/Projects/github/mine/gung-ho') | |
FileUtils.mkdir_p dir | |
dir | |
end | |
class SimpleCov::Formatter::MergedFormatter | |
def format(result) | |
SimpleCov::Formatter::HTMLFormatter.new.format(result) | |
SimpleCov::Formatter::RcovFormatter.new.format(result) | |
File.open("#{coverage_directory}/covered_percent", "w") do |f| | |
f.puts result.source_files.covered_percent.to_f | |
end | |
end | |
end | |
SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter | |
SimpleCov.configure do | |
coverage_dir 'doc/coverage' | |
root '/Users/roy/Projects/github/mine/gung-ho' | |
end | |
SimpleCov.start do | |
add_filter '/spec/' | |
add_filter '/features/' | |
# add_filter '/lib/' | |
# | |
add_group 'Controllers', 'lib/gung_ho/controller' | |
add_group 'Models', 'lib/gung_ho/model' | |
add_group 'Helpers', 'lib/gung_ho/helper' | |
add_group 'Views', 'lib/gung_ho/view' | |
add_group 'Configs', 'lib/gung_ho/config' | |
end | |
#SimpleCov.start |
This file contains 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_relative '../simplecov_helper.rb' if ENV['COVERAGE'] == 'true' | |
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | |
$LOAD_PATH.unshift(File.dirname(__FILE__)) | |
ENV['APP_ENV'] = 'test' | |
require 'ramaze' | |
require 'rack' | |
require 'rack/test' | |
require "rspec" | |
require 'json' | |
require 'capybara' | |
require 'capybara/rspec' | |
require 'database_cleaner' | |
require 'gung-ho' | |
require_relative('../lib/gung_ho/app') | |
# Tells Capybara which driver to use and where to find your application. | |
# Without this Capybara will not work properly. | |
Capybara.configure do |config| | |
config.default_driver = :rack_test | |
config.app = Ramaze | |
end | |
Ramaze::Log.level = Logger::INFO | |
RSpec.configure do |config| | |
config.mock_with :rspec | |
config.include Rack::Test::Methods | |
config.before(:all) do | |
Ramaze::Current.session = Rack::Test::Session.new(Rack::MockSession.new(app)) | |
@session = Ramaze::Current.session | |
DatabaseCleaner[:mongo_mapper].strategy = :truncation | |
DatabaseCleaner.clean | |
User.setup | |
Site.setup | |
end | |
config.after(:all) do | |
DatabaseCleaner.clean | |
end | |
def app | |
Ramaze.setup_dependencies | |
Rack::Lint.new Ramaze | |
end | |
end | |
app = Ramaze | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment