I am working with the Shopsense Ruby Gem however I am unable to use the gem. Making requests exactly as in the test I receive the following error:
/Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:455:in `block in get_response': undefined method `request_uri' for #<URI::Generic:0x007fd5b3a66810> (NoMethodError)
from /Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /Users/rudolph9/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:454:in `get_response'
from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/Shopsense-0.1.1/lib/Shopsense.rb:76:in `do_search'
from test_shopsense.rb:10:in `<main>'
However, the test works fine if I clone the repository, modify the test and require the source directly as follows:
1 #!/usr/bin/env ruby¬
2 require 'rubygems'¬
3 #require 'Shopsense'¬
4 require '../lib/shopsense.rb'¬
.
.
.
What is the issue when using the gem it self??
Do you have an older version of the gem installed, or another gem which is named Shopsense?
With the error you're getting, I suspect the issue would be related ruby trying to automatically find the gem when you do require 'Shopsense' and finding something other than what you want. When you do require '../lib/shopsense.rb' it defines a specific path to the gem, so you always get the gem you want.
I don't have any experience with Shopsense, but the link you supplied looks like its a version 0.1.0, while the ruby interpreter found a Shopsense-0.1.1. I suspect the issue has to do with that. In fact, the source for Shopsense you linked to, line 76 (where the error is in your output) is a blank line.
Related
I'm using this gem called gmail and it works perfectly when run in just a plain ruby script. However, when used inside Rspec, I keep getting this error.
Failure/Error: #gmailnew = Gmail.new()
LoadError:
cannot load such file -- gmail/client
# /Library/Ruby/Gems/2.0.0/gems/gmail-0.6.0/lib/gmail.rb:50:in new'
# ./temp.rb:7:inblock (2 levels) in '
Any idea what causes this?
- I've already tried reinstalling it since it seems to be not finding a file.
I could not figure out what causes the conflict, similar problems by others.
Why is autoload failing to load files for gems
Ruby autoload conflicts between gmail and parse_resource gems
I was able to resolve this by using Bundler.
1) Added gem inside the Gemfile (gem 'gmail')
2) $ bundle install - this installs all gems inside the Gemfile, and avoids the conflicts
3) $ bundle exec rspec my_spec_file.rb - executes Rspec
I’m running on Mac OS X Yosemite 10.10 Beta 3, I did a fresh install of rvm (removed everything I could think of and reinstalled the whole thing.
Attempting to run a scripts I had working on Mavericks.
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ gem install restclient
Successfully installed restclient-0.10.0
Parsing documentation for restclient-0.10.0
Done installing documentation for restclient after 0 seconds
1 gem installed
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ which irb
/Users/maximveksler/.rvm/rubies/ruby-2.1.2/bin/irb
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ irb
2.1.2 :001 > require 'restclient'
LoadError: cannot load such file -- restclient
from /Users/maximveksler/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/maximveksler/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from (irb):1
from /Users/maximveksler/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>’
Path looks normal
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ env | grep GEM
GEM_HOME=/Users/maximveksler/.rvm/gems/ruby-2.1.2
GEM_PATH=/Users/maximveksler/.rvm/gems/ruby-2.1.2:/Users/maximveksler/.rvm/gems/ruby-2.1.2#global
Also the gem is installed
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ file /Users/maximveksler/.rvm/gems/ruby-2.1.2/gems/restclient-0.10.0/lib/rest_client.rb
/Users/maximveksler/.rvm/gems/ruby-2.1.2/gems/restclient-0.10.0/lib/rest_client.rb: ASCII C++ program text
So what am I missing ?
Looking at your link here, there is an error in your syntax. It should be require 'rest_client' rather than require 'restclient'. The reason that your version still works is as you said because there is a file called restclient.rb which is used as the source for the additional restclient binary that the gem supplies (which is against regular naming convention, you should file an issue with the github).
Now because you require this file (restclient.rb) which is used to set up an environment that already has RestClient available, it is effectively the same as requiring rest_client. It may however have unintended consequences so you should probably stick to the convention outlined in the documentation.
This is all from reading the documentation here and glancing at the files here. Does that make sense? I worried it was unclear as the two files are very similar.
This works:
[rails31]$ ruby -S rspec ./spec/models/domain_spec.rb
*.
Pending:
Domain add some examples to (or delete) /home/keith/Code/elements2/spec/models/domain_spec.rb
# Not Yet Implemented
# ./spec/models/domain_spec.rb:4
Finished in 0.04241 seconds
2 examples, 0 failures, 1 pending
However I'm trying to run from guard, which executes the following command:
[rails31]$ /home/keith/.rbenv/versions/1.9.2-p290/bin/ruby -S rspec ./spec/models/domain_spec.rb
/home/keith/.rbenv/versions/1.9.2-p290/bin/ruby: no Ruby script found in input (LoadError)
Breaking that down enough to execute I get this:
[rails31]$ /home/keith/.rbenv/versions/1.9.2-p290/bin/ruby ./spec/models/domain_spec.rb
/home/keith/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rspec-core-2.8.0.rc1/lib/rspec/core/configuration.rb:335:in `rescue in debug=': (RuntimeError)
**************************************************
no such file to load -- ruby-debug
If you have it installed as a ruby gem, then you need to either require
'rubygems' or configure the RUBYOPT environment variable with the value
'rubygems'.
...
This is actually where I started in the first place - I know rspec respects the "dont require rubygems" rule, so maybe I need to run rake. The big problem I have with this error is that "ruby-debug" does NOT exist for ruby1.9 - it should be ruby-debug19 - so whats happening here?
So anyway, I tried with Rake:
[rails31]$ rake spec ./spec/models/domain_spec.rb
(in /home/keith/Code/elements2)
rake aborted!
uninitialized constant Rake::DSL
...
I've tried Googling the problem but nothing obvious is coming up, so really I'm stumped
UPDATE:
Well after reading this post I've managed to resolve the rake issue, however now when I run rake I get this:
[rails31]$ rake spec
(in /home/keith/Code/elements2)
/home/keith/.rbenv/versions/1.9.2-p290/bin/ruby -S rspec ./spec/models/domain_spec.rb
/home/keith/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rspec-core-2.8.0.rc1/lib/rspec/core/configuration.rb:335:in `rescue in debug=': (RuntimeError)
...
I've just installed RubyMine, as long as Ruby + gem + rspec + rspec-rails.
I'm trying to make run the mini-tutorial shown on http://rspec.info/ but I'm having problems.
First, I had to modify the shown
require 'bowling'
to
require_relative 'bowling'
as I was getting a
`require': no such file to load -- bowling.
Now, even after doing this I am getting a
`<top (required)>': undefined method `describe' for main:Object (NoMethodError)
How to make rspec work in RubyMine?
rspec.info is for RSpec version 1.x. Documentation for 2.x, which is what you will have installed if you simply did gem install rspec can be found at http://relishapp.com/rspec. You may want to take a look at their tutorial there.
I use RSpec and RubyMine together every day, so I expect that version mismatch is your biggest problem.
Also, if you are willing to purchase a book to learn RSpec, I'd highly recommend http://pragprog.com/book/achbd/the-rspec-book from Pragmatic Programmers.
Well, it seems to be a known issue:
http://youtrack.jetbrains.net/issue/RUBY-8603?projectKey=RUBY
EDIT: it did indeed seem to work.
I'm trying to add a new gateway to the active_merchant gem and I'm having 'require' issues when I try to run it from source.
(I think my problem is not active_merchant-specific, but more of a general Ruby environment issue, so I dont think the specific gem in use has to do with it.)
This is what I've done:
Cloned the Git repo for AM, to my local directory "C:\Users\jb\Documents\Aptana Studio 3 Workspace\active_merchant"
Went about doing the changes in the "billing/gateways" directory (this is just background info..)
Copied the "Sample Usage" example on AM's Git repo to C:\Users\jb\Documents\Aptana Studio 3 Workspace\simple_gw_test.rb, which starts with:
require 'rubygems'
require 'active_merchant'
Ran "ruby simple_gw_test.rb" and got the error message:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
active_merchant (LoadError)
from <internal:lib/rubygems/custom_require>:29:in 'require'
from simple_gw_test.rb:3:in '<main>'
This is understandable, since I don't have active_merchant gem installed
However, I want to use the downloaded source in the sample file, since I'm modifying the gateway source continually.
I tried
require '/Users/jb/Documents/Aptana Studio 3 Workspace/active_merchant'
And then got the same error:
<internal:lib/rubygems/custom_require>:29:in require': no such file to load --
/Users/jb/Documents/Aptana Studio 3 Workspace/active_merchant (LoadError)
from <internal:lib/rubygems/custom_require>:29:inrequire'
from simple_gw_test.rb:2:in `<main>';
Any Ruby Guru who can shed some light greatly appreaciated!
--jb
PS: I'm using MRI 1.9.2 on Windows 7 x64.
Make sure you have read access to that file. Ruby has given me that error before when I didn't have correct permissions.
I guess I scratched my own itch: After a couple of hours of "Pickaxe book-ing" and googling, I got the code necessary to bootstap the gem without it being installed:
require_relative 'active_merchant/lib/active_merchant'