Created
April 1, 2012 22:29
-
-
Save TildeWill/2279150 to your computer and use it in GitHub Desktop.
File exist problem with Coderay
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
describe "xml data", :document => true do | |
before do | |
test_client.get "/xml" | |
end | |
it "should handle xml data" do | |
test_client.last_response.headers["Content-Type"].should =~ /application\/xml/ | |
end | |
it "should log the request" do | |
example.metadata[:requests].first[:route].should == "/xml" | |
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 'coderay' | |
module RspecApiDocumentation | |
class TestClient < Struct.new(:session, :options) | |
#... | |
private | |
def document_example(method, action, params) | |
#... | |
request_metadata[:response_body] = formatted_response_body(last_response.body, last_response.headers['Content-Type']) | |
#... | |
end | |
#... | |
def formatted_response_body(body, content_type) | |
options = {}#{:line_numbers => :table} | |
begin | |
case content_type | |
when /xml/ | |
CodeRay.scan(body, :xml).div(options) | |
when /html/ | |
CodeRay.scan(body, :html).div(options) | |
when /json/ | |
CodeRay.scan(JSON.pretty_generate(JSON.parse(body)), :json).div | |
when /javascript/ | |
CodeRay.scan(JSON.pretty_generate(body), :javascript).div(options) | |
when /image|jpg|jpeg|gif|png|bmp|binary/ | |
"<img src=\"data:binary/octet;base64,#{Base64.encode64(body)}\" />" | |
else | |
body | |
end | |
rescue | |
last_response.body | |
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
def make_plugin_hash | |
@plugin_map_loaded ||= false | |
Hash.new do |h, plugin_id| | |
id = validate_id(plugin_id) | |
path = path_to id | |
begin | |
raise LoadError, "#{path} not found" unless File.exist? path #File.exist? returns false even though the file is there when running my spec | |
require path | |
rescue LoadError => boom | |
if @plugin_map_loaded | |
if h.has_key?(:default) | |
warn '%p could not load plugin %p; falling back to %p' % [self, id, h[:default]] | |
h[:default] | |
else | |
raise PluginNotFound, '%p could not load plugin %p: %s' % [self, id, boom] | |
end | |
else | |
load_plugin_map | |
h[plugin_id] | |
end | |
else | |
# Plugin should have registered by now | |
if h.has_key? id | |
h[id] | |
else | |
raise PluginNotFound, "No #{self.name} plugin for #{id.inspect} found in #{path}." | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
require 'coderay' causes: