I am getting following error when running a test file.
$ruby test/test_gothonweb.rb
/Users/sony/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- rack/test (LoadError)
from /Users/sony/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test/test_gothonweb.rb:3:in `<main>'
Snippet of the test file:
require_relative '../lib/gothonweb.rb'
require 'test/unit'
require 'rack/test'
ENV['RACK_ENV'] = 'test'
class GothonwebTest < Test::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application
end
end
I think the gem is installed and should be available:
gem list
*** LOCAL GEMS ***
bundler (1.1.3)
rack (1.4.1)
rack-protection (1.2.0)
rake (0.9.2.2)
rubygems-bundler (0.9.0)
rvm (1.11.3.3)
sinatra (1.3.2)
tilt (1.3.3)
Why the error you think?
rack-test is a separate gem. Include that in your Gem file.
Had similar issue here, and by gem uninstall rack-test and then bundle install solved the issue.
https://github.com/brynary/rack-test/issues/123
Related
I'm trying to format my output as json. Here is a test code from http://www.sinatrarb.com/contrib/json.html :
require "sinatra"
require "sinatra/json"
# define a route that uses the helper
get '/' do
json :foo => 'bar'
end
# The rest of your classic application code goes here...
It shows me an "Application Error". Maybe it comes from the other files to launch the app. I'm using heroku(cloud). So I have a Gemfile :
source 'https://rubygems.org'
gem 'sinatra', '1.1.0'
gem 'thin'
Gemfile.lock :
GEM
remote: https://rubygems.org/
specs:
daemons (1.1.9)
eventmachine (1.0.3)
rack (1.5.2)
sinatra (1.1.0)
rack (~> 1.1)
tilt (~> 1.1)
thin (1.5.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.4.1)
PLATFORMS
ruby
DEPENDENCIES
sinatra (= 1.1.0)
thin
and Procfile :
web: bundle exec ruby web.rb -p $PORT
Did I miss something ?
You need to reference in your Gemfile json gem, e.g:
gem "json", "1.5.5"
And then you call .to_json on the object you want to output as JSON.
I'm developing a gem. There is a folder titled /spec and it contains 2 files:
#spec_helper.rb
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'my_gem'
#my_gem_spec.rb
describe MyGem do
it 'should have a version number' do
MyGem::VERSION.should_not be_nil
end
#............
end
Then I run it
rspec spec
/var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:491:in `add_formatter': Formatter 'specdoc' unknown - maybe you meant 'documentation' or 'progress'?. (ArgumentError)
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration_options.rb:30:in `block in configure'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration_options.rb:30:in `each'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration_options.rb:30:in `configure'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:21:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:80:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:17:in `block in autorun'
What does it mean? How to get rid of it?
Here is the bundle's output
bundle install
Using rake (10.0.3)
Using diff-lcs (1.1.3)
Using my_gem (0.0.1) from source at .
Using rspec-core (2.12.2)
Using rspec-expectations (2.12.1)
Using rspec-mocks (2.12.1)
Using rspec (2.12.0)
Using bundler (1.3.0.pre.4)
Uninstall all previous versions of rspec and its dependencies.
gem uninstall rspec
gem uninstall rspec-core
gem uninstall rspec-mocks
gem uninstall rspec-expectations
Install the correct version of rspec in gem file install rspec.
group :development, :test do
gem 'rspec-rails', '~> 3.0.0'
end
see this answer
I've got a simple script that uses sinatra. Should be simple, right? Apparently not.
The code:
require 'rubygems'
require 'sinatra'
That's all there is. And it fails, saying:
tekknolagi#eos ~/indexer $ ruby torrent.rb
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- torrent-ruby (LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from torrent.rb:2
I gem installed it several times over, just to make sure I wasn't going crazy. What could be going wrong and how can I fix it?
Oh, and here's my list of installed gems:
tekknolagi#eos ~/indexer $ gem list
*** LOCAL GEMS ***
rack (1.4.1)
rack-protection (1.2.0)
rake (0.9.2.2)
sinatra (1.3.2)
sqlite3 (1.3.6)
tilt (1.3.3)
torrent-ruby (0.1.4)
I believe you have done everything right. Many times this custom require error appears when the gem is not installed in the proper path. Try not using the explicit require. Use this instead..:
require_relative 'sinatra'
I was trying to learn about the Sinatra ruby framework by following this tutorial:
http://net.tutsplus.com/tutorials/ruby/singing-with-sinatra-the-recall-app-2/
however, after running the gem install and writing a simple sinatra server in test.rb like so:
require 'sinatra'
require 'datamapper'
get '/' do
"Hello, World!"
end
but when I run the command ruby test.rb, I get the following error:
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- datamapper (LoadError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from datamapper_test.rb:2:in `<main>'
glenn#ubuntu:~/Dropbox/Repositories/sandbox/sinatra$ ruby datamapper_test.rb
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- datamapper (LoadError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test.rb:3:in `<main>'
it seems as though it cannot find the datamapper gem. how can I fix this?
EDIT: using ruby 1.9.2
EDIT (again): (parital) output from gem list:
data_mapper (1.2.0)
data_objects (0.10.8)
datamapper (1.2.0)
devise (1.4.5)
directory_watcher (1.4.0)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.0)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-serializer (1.2.1)
dm-sqlite-adapter (1.2.0)
d m-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.1)
dm-validations (1.2.0)
do_sqlite3 (0.10.8)
sinatra (1.3.2, 1.2.6)
sqlite3 (1.3.5, 1.3.4)
sqlite3-ruby (1.3.3)
You need to require 'data_mapper', not datamapper.
Note there is a datamapper gem as well as a data_mapper gem, but they are the same thing, just different names. You need use data_mapper as the library name in both of them.
As far as I can tell datamapper is a straight copy of data_mapper:
$ diff -r data_mapper-1.2.0/ datamapper-1.2.0/
diff -r data_mapper-1.2.0/Rakefile datamapper-1.2.0/Rakefile
21c21
< GEM_NAME = 'data_mapper'
---
> GEM_NAME = 'datamapper'
gem install datamapper in your terminal might help :)
But you will also need a database and an adapter and you will want to use the gem somehow. Good luck and have fun with dm + sinatra!
I successfully installed gem clockwork
C:\web>gem install clockwork
Successfully installed clockwork-0.2.3
1 gem installed
Installing ri documentation for clockwork-0.2.3...
Installing RDoc documentation for clockwork-0.2.3...
but when running simple script
require 'rubygems'
require 'clockwork'
include Clockwork
every(1.minute, 'custom.event.handler' ) do
puts "This event has its own handler - #{Time.new.strftime("%Y%m%d%H%M%S")}"
end
I get this error
C:\web>ruby clockwork.rb
./clockwork.rb:3: uninitialized constant Clockwork (NameError)
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
from clockwork.rb:2
Any suggestion how to make clockwork work on
Windows XP
ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
gem 1.3.7
C:\web>gem list --local
*** LOCAL GEMS ***
aaronh-chronic (0.3.9)
activesupport (3.0.9)
backports (1.18.2)
clockwork (0.2.3)
daemons (1.1.0)
delayed_job (2.0.3)
eventmachine (0.12.10 x86-mswin32-60)
fastercsv (1.5.4)
haml (3.0.21)
i18n (0.6.0)
json (1.5.1)
mechanize (1.0.0)
monkey-lib (0.5.4)
nokogiri (1.5.0 x86-mingw32, 1.4.3.1 x86-mingw32)
rack (1.2.1)
rdiscount (1.6.8)
ruby-growl (3.0)
sinatra (1.2.6, 1.0)
sinatra-advanced-routes (0.5.1)
sinatra-reloader (0.5.0)
sinatra-sugar (0.5.1, 0.5.0)
thin (1.2.7 x86-mswin32)
tilt (1.3)
Let me give you a hint. The name of your own program is clockwork.rb, and in it you do:
require 'clockwork'
See the problem?
you need to include the following in your clock.rb
require './config/boot'
require './coonfig/environment'