Skip to content

Instantly share code, notes, and snippets.

@TildeWill
Created April 1, 2012 22:29
Show Gist options
  • Save TildeWill/2279150 to your computer and use it in GitHub Desktop.
Save TildeWill/2279150 to your computer and use it in GitHub Desktop.
File exist problem with Coderay
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
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
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
@TildeWill
Copy link
Author

require 'coderay' causes:

 CodeRay::PluginHost::PluginNotFound:
   CodeRay::Scanners could not load plugin :json: /Users/readwl/.rvm/gems/ruby-1.9.2-p180@rspecapidocumentation/gems/coderay-1.0.5/lib/coderay/scanners/json.rb not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment