I am trying to run the unit tests of the ActiveMerchant gem version
1.4.1: https://github.com/Shopify/active_merchant/tree/v1.4.1
First I ran: rake -T and got the error:
uninitialized constant ActiveMerchant::Validateable::HashWithIndifferentAccess
I fixed that first error by adding:
gem 'activesupport', "=2.3.4"
require 'active_support'
at the top of the Rakefile(https://github.com/Shopify/active_merchant/blob/v1.4.1/Rakefile). Note that I had to specify the exact version (I guess HashWithIndifferentAccess doesn't exist in later versions of ActiveSupport).
Now, if I run: rake test:units, I get the same error:
uninitialized constant ActiveMerchant::Validateable::HashWithIndifferentAccess
Here is the task that it tries to run (in the same Rakefile):
Rake::TestTask.new(:units) do |t|
t.pattern = 'test/unit/**/*_test.rb'
t.ruby_opts << '-rubygems'
t.verbose = true
end
How can I get rid of this error? Do I need to specify the activesupport gem inside the task?
gem 'activemerchant' # => Ruby 1.9.2 / AM 1.12.x
vs
gem 'active_merchant' # => ? / AM 1.5.2
ActiveMerchant is on version 1.12.0, so 1.4.1 is quite old - have you tried this with the latest version?
Related
I have two Ruby projects (1 Rails, 1 vanilla). Both using Ruby 3.0.3. In my Ruby project (before bundling my Rails one), Minitest::Pride is loaded and works when running rake test. But, after bundling the Rails project, I'm back to old red/green colors for rake test in the Ruby project.
Here's the file structure (for simplicity's sake, I'm stripping the Rails project down to just a Gemfile, which I can reproduce this error with on a clean Ruby Rbenv install):
ruby-project/
-- test/
-- example_test.rb
-- test_helper.rb
Gemfile
Rakefile
rails-project/
-- Gemfile
ruby-project/test/example_test.rb:
require "test_helper"
class ExampleTest < Minitest::Test
25.times do |i|
define_method "test_success#{i}" do
assert true
end
end
end
ruby-project/test/test_helper:
require "minitest/autorun"
require "minitest/pride"
ruby-project/Gemfile:
source "https://rubygems.org"
gem "rake"
gem "minitest"
ruby-project/Rakefile:
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs = %w(lib test)
t.pattern = "test/**/*_test.rb"
end
task :default => :test
rails-project/Gemfile:
source "https://rubygems.org"
ruby "3.0.3"
gem "rails", "~> 7.0.3"
Steps to Reproduce (with rbenv already installed):
Build two projects like the ones above
rbenv install 3.0.3
From ruby-project dir: bundle
From ruby-project dir: rake test (Minitest::Pride plugin loaded)
From rails-project dir: bundle
From ruby-project dir: rake test (Minitest::Pride plugin NOT loaded)
Things I have tried:
locking Minitest to the exact same version for both projects (5.16.3 and 5.17.0)
locking Rails to 7.0.3.1 and 7.0.4.2
Bundling the Rails project first
I'm running on a M1 Mac, but I'm not sure this matters. Interestingly, rails test in a real Rails project WILL load Minitest::Pride.
Any ideas on what's going on and how to fix?
I'm trying to do the labs on TestFirst.org with rspec. I've installed rspec and initilized it in the project directory. But when i "rake" i get this error message:
Could not find 'rspec' <~> 2) - did find: [rspec-3.0.0]
C:/Sites/RubyTest/RubyTesting/learn_ruby/rakefile:2:in `<top (required)>´
My versions:
ruby 1.9.3p545
rails 4.1.1
rspec 3.0.2
Seems like I've got the wrong version of rspec or something. My OS is windows 7 btw.
This is the content of rakefile:
gem 'rspec', '~>2'
require 'rspec/core/rake_task'
task :default => :spec
desc "run tests for this lab"
RSpec::Core::RakeTask.new do |task|
lab = Rake.application.original_dir
task.pattern = "#{lab}/*_spec.rb"
task.rspec_opts = [ "-I#{lab}", "-I#{lab}/solution", '-f documentation', '-r ./rspec_config']
task.verbose = false
end
This is because rspec ~3.0.0 is already activated and your rake file requires 'rspec', '~>2'. Change rspec version in Rakefile to fix this.
gem 'rspec', '~>3'
Looks like you have a installed version of rspec (3.0.2) that is more recent than the one expected by the project (~ 2.x).
One simple way to solve it would be to force bundle to use the project version:
bundle exec rake
(instead of just using rake)
trying to use in rails3.2.14 and ruby 1.9.3
added gem ’preferences’ to Gemfile and did bundle install
And as per the gem document I do the following step
rails generate migration create_preference
ran rake db:migrate
restarted rails server
added some preference to user model
preference :publish_profile, :default => true
But when tried to access a preference using
#user.prefers_publish_profile
I got uninitialized constant Preferences::InstanceMethods::Preference
Here is the gem url:-
https://github.com/pluginaweek/preferences
The problem will besolved by using rails3 branch gem
gem "preferences", :git
=>"git#github.com:skyeagle/preferences.git",:branch =>"rails3"
Thanks
In my Gemfile I have:
gem 'addressable'
In search_controller.rb:
uri = Addressable::URI.new
uri.query_values = {:q => query}
I get this error:
NameError (uninitialized constant SearchController::Addressable):
If I put
require 'addressable/uri'
on top of my controller, it works!!. I have already done "sudo bundle install" and it shows addressable is installed. What am I doing wrong?
Looking at addressable gem source I see it has no lib/addressable.rb which is default file which rubygems or bundler require when loading required gem. So it looks like it is designed this way on purpose - to make you explicitly require only the libraries you need.
In a previous question, I asked how to tell my Gemfile whether to take the JRuby-relevant gems or the MRI-relevant gems. The answer I got was to do the following in the Gemfile:
platforms :jruby do
gem "activerecord-jdbcsqlite3-adapter"
end
platforms :mri do
gem "sqlite3"
end
Obviously, the platforms() method in Bundler knows how to figure out if I'm running MRI or JRuby. Is there another way I can tell within my program if I am running JRuby or MRI?
Are you able to distinguish between the two like this:
case (RUBY_ENGINE)
when 'ruby'
# ...
when 'jruby'
# ...
end
You could write a method to give you a jruby? method if required:
def jruby?
RUBY_ENGINE == 'jruby'
end
With Ruby 2.2.3 Config::CONFIG gives me NameError: uninitialized constant Config, but the following works:
y RbConfig::CONFIG