.worker file
runtime "ruby"
name "UserMailer"
merge_gem "activerecord", "=3.2.8"
merge_gem 'actionmailer', '=3.2.8'
merge_gem 'devise', '=2.1.2'
merge_gem 'pg', "=0.14.0"
merge_file "../app/views/user_mailer/new_user.html.erb" , "user_mailer"
merge_file "../app/mailers/user_mailer.rb"
merge_dir "../app/models"
merge_exec "user_mailer_worker.rb"
.rb file
require 'action_mailer'
require 'active_record'
require 'pg'
require 'bcrypt'
require 'devise'
require 'user_mailer.rb'
require 'models/user.rb'
def init_mailer
#Need to convert to proper hashes
mailer_config = params['mailer'].inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo }
# set default views dir to current dir
ActionMailer::Base.prepend_view_path('.')
ActionMailer::Base.smtp_settings = mailer_config
ActionMailer::Base.delivery_method = :smtp
end
def setup_database
puts "Database connection details:#{params['database'].inspect}"
return unless params['database']
# estabilsh database connection
ActiveRecord::Base.establish_connection(params['database'])
end
init_mailer
setup_database
puts "I got '#{params.inspect}' parameters"
#send email!
# you could use here any active_record queries with models
UserMailer.new_user(User.find(params[:id])).deliver!
I have uploaded code to iron worker but i got following output
Skipping ruby gem with name='pg' and version='0.14.0' as it contains native extensions, switching to full remote build should fix this
and after i queue task on iron.io i got error
/usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- pg (LoadError)
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /task/user_mailer_worker.rb:4:in `<top (required)>'
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from __runner__.rb:190:in `<main>'
how to require 'pg' gem on iron.io ??
Add this line to .worker file:
full_remote_build true
Related
First i read other posts of users with similiar problems, but couldnt come along where my mistake is. I wanted to start a test with RSpec on the following file:
dashboard_view_spec.rb:
require 'rails_helper'
RSpec.feature "Dashboard", type: :feature do
before(:each) do
#current_user = User.create!(email: "xyz#xyz.com", password: "xyz123")
sign_in_with(#current_user.email,#current_user.password)
end
#NAV BAR RSPEC TEST
scenario 'Home bar nav link present' do
visit "/"
expect(page).to have_text('Home')
end
scenario 'How it work nav bar link present' do
visit "/"
expect(page).to have_text('How it work')
end
scenario 'Support nav bar link present' do
visit "/"
expect(page).to have_text('Support')
end
end
On rails_helper.rb on the top:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rake'
require 'spec_helper'
require 'rspec/rails'
require 'shoulda/matchers'
require 'capybara/rails'
require 'capybara/rspec'
require 'rspec/retry'
require 'devise'
Error message:
Failure/Error: require File.expand_path('../../config/environment', __FILE__)
NoMethodError:
undefined method `[]' for nil:NilClass
# ./config/initializers/devise.rb:258:in `block in <top (required)>'
# ./config/initializers/devise.rb:5:in `<top (required)>'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/views/dashboard_view_spec.rb:1:in `require'
# ./spec/views/dashboard_view_spec.rb:1:in `<top (required)>'
No examples found.
Randomized with seed 14549
Then the command i used on the terminal
bundle exec rspec spec/views/dashboard_view_spec.rb
After watching the documentation of testing with Devise i changed the code in dashboard_view_spec.rb and used to sign_in as a user and got the same error message.
Line 258 of devise.rb
config.omniauth :facebook, Rails.application.secrets.facebook[:key], Rails.application.secrets.facebook[:secret], scope: 'email', info_fields: 'email, name'
In the gemfile
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
gem 'rspec-rails', '~> 3.8'
gem 'factory_girl_rails'
gem 'faker'
gem 'database_cleaner'
end
and
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
The problem is that you're missing a variable that your devise initializer expects to find, but only missing it in the test environment. (not the development environment)
The stack trace that you provided and line 258 from config/initializers/devise.rb are all that are needed. First, let's look at the stack trace:
NoMethodError:
undefined method `[]' for nil:NilClass
# ./config/initializers/devise.rb:258:in `block in <top (required)>'
# ./config/initializers/devise.rb:5:in `<top (required)>'
# ./config/environment.rb:5:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
# ./spec/views/dashboard_view_spec.rb:1:in `require'
# ./spec/views/dashboard_view_spec.rb:1:in `<top (required)>'
Starting from the bottom up, we can see that the first line of your spec is what's causing the issue. If you follow the stack you'll see that it ends up in config/initializers/devise.rb:258 and is complaining that something making a [] method call isn't getting the expected object type in return, and is instead getting nil in return.
Looking at line 258 you find:
config.omniauth :facebook, Rails.application.secrets.facebook[:key], Rails.application.secrets.facebook[:secret], scope: 'email', info_fields: 'email, name'
So you can see that there are two times that [] is called:
Rails.application.secrets.facebook[:key]
Rails.application.secrets.facebook[:secret]
What is expected is that calling Rails.application.secrets.facebook will return an Enumerable object (like an array or a hash) but instead it is returning nil, and when it attempts to run nil[:key] or nil[:secret] it raises an exception because NilClass is not an Enumerable and does not have a [] method. You can test this yourself in the rails console:
nil[:secret]
=> NoMethodError: undefined method `[]' for nil:NilClass
The solution is to ensure that calling Rails.application.secrets.facebook returns the expected object type. The short answer is to edit config/secrets.yml to ensure that the values you require for the test environment are present.
I haven't worked with devise in a long time, but I assume that you can safely use the same values that you're using for the development environment for the test environment. You can read more about secrets() elsewhere, but the basic template for config/secrets.yml is as follows:
environment:
key: value
For example:
test:
my_secret_key: my_secret_value
It should be fairly straightforward to copy and paste the missing facebook secrets into the test environment. After making the change you can verify it worked:
$ RAILS_ENV=test rails console
Rails.application.secrets.facebook[:key]
=> <your key here>
If that worked, then run your spec with rspec and it should successfully get past line 1. (assuming there are no other bugs or missing secrets)
I had very similar errors. Here's how I solved
Run rspec --backtrace
This could produce a lot of console output. Scroll right to the top, and start reading from the top. It will tell you the file your problem started in, and the line it happened on. Go to that file (and that line), and figure out what's missing.
In my case, it was actually a missing variable in credentials.yml, but cases will vary. Like in the excellent answer by #anothermh, it's basically telling you something is missing, so you have to figure out what's missing and make sure you provide it.
Just got the same error, but when I ran bundle exec rake spec instead of bundle exec rspec it worked.
I created a ruby on rails project at /home/web/Rubyonrails
When run rails server then got below errors:
web#web-VirtualBox:~/Rubyonrails$ rails server
/home/web/Rubyonrails/config/application.rb:19:in `block in <top (required)>': undefined local variable or method `config' for main:Object (NameError)
from /home/web/Rubyonrails/config/application.rb:18:in `tap'
from /home/web/Rubyonrails/config/application.rb:18:in `<top (required)>'
from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in `require'
from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:88:in `block in server'
from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:85:in `server'
from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /home/web/.rvm/gems/ruby-2.4.0/gems/railties-5.0.2/lib/rails/commands.rb:18:in `<top (required)>'
from /home/web/Rubyonrails/bin/rails:9:in `require'
from /home/web/Rubyonrails/bin/rails:9:in `<top (required)>'
from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
from /home/web/.rvm/gems/ruby-2.4.0/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
from /home/web/Rubyonrails/bin/spring:15:in `require'
from /home/web/Rubyonrails/bin/spring:15:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
config/application.rb file:
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Rubyonrails
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
end
end
# Bower asset paths
Rails.root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
config.sass.load_paths << bower_path
config.assets.paths << bower_path
end
# Precompile Bootstrap fonts
config.assets.precompile << %r(bootstrap-sass/assets/fonts/bootstrap/[\w-]+\.(?:eot|svg|ttf|woff2?)$)
# Minimum Sass number precision required by bootstrap-sass
::Sass::Script::Value::Number.precision = [8, ::Sass::Script::Value::Number.precision].max
Rubyonrails/bin/rails file looks like:
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
Rubyonrails/bin/spring file looks like:
#!/usr/bin/env ruby
# This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.
unless defined?(Spring)
require 'rubygems'
require 'bundler'
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
spring = lockfile.specs.detect { |spec| spec.name == "spring" }
if spring
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
gem 'spring', spring.version
require 'spring/binstub'
end
end
Change line 18 of your config/application.rb to:
Rails.root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
root is not defined, but Rails.root is.
In application.rb
# Bower asset paths
root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
config.sass.load_paths << bower_path
config.assets.paths << bower_path
end
you are missing Rails before root:
# Bower asset paths
Rails.root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
config.sass.load_paths << bower_path
config.assets.paths << bower_path
end
If you have to run
source /home/web/.rvm/scripts/rvm
every time you open a window then you haven't installed RVM correctly.
Carefully read "Installing RVM" and confirm you followed those steps.
Once you've confirmed that the installation is correct you need to set a default Ruby for RVM to use. First, list the Rubyies RVM manages:
rvm list
which returns something like:
rvm rubies
=* ruby-2.4.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
then tell RVM to use one:
rvm use ruby-2.4.0 --default
Also, it's a good idea to periodically tell RVM to update itself. Run
rvm help get
at the command-line for more information.
I am trying to setup rspec (v3.0.2) on Rails 4.1.9 with factory_girl_rails but after implementing rails_helper.rb and spec_helper.rb I get the following error when running my _spec.rb file:
/Users/user/.rvm/gems/ruby-2.2.1/gems/activerecord-4.1.9/lib/active_record/attribute_methods.rb:9:in `<module:AttributeMethods>': uninitialized constant ActiveModel::AttributeMethods (NameError)
from /Users/user/.rvm/gems/ruby-2.2.1/gems/activerecord-4.1.9/lib/active_record/attribute_methods.rb:7:in `<module:ActiveRecord>'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/activerecord-4.1.9/lib/active_record/attribute_methods.rb:5:in `<top (required)>'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/activerecord-4.1.9/lib/active_record.rb:101:in `<module:ActiveRecord>'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/activerecord-4.1.9/lib/active_record.rb:31:in `<top (required)>'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/activerecord-4.1.9/lib/active_record/railtie.rb:1:in `require'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/activerecord-4.1.9/lib/active_record/railtie.rb:1:in `<top (required)>'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/all.rb:12:in `require'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/all.rb:12:in `block in <top (required)>'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/all.rb:10:in `each'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/railties-4.1.9/lib/rails/all.rb:10:in `<top (required)>'
from /Users/user/code/rtb-campaign-optimization/config/application.rb:3:in `require'
from /Users/user/code/rtb-campaign-optimization/config/application.rb:3:in `<top (required)>'
from /Users/user/code/rtb-campaign-optimization/config/environment.rb:2:in `require'
from /Users/user/code/rtb-campaign-optimization/config/environment.rb:2:in `<top (required)>'
from /Users/user/code/rtb-campaign-optimization/spec/rails_helper.rb:4:in `require'
from /Users/user/code/rtb-campaign-optimization/spec/rails_helper.rb:4:in `<top (required)>'
from /Users/user/code/rtb-campaign-optimization/spec/models/cpa_calculator_spec.rb:1:in `require'
from /Users/user/code/rtb-campaign-optimization/spec/models/cpa_calculator_spec.rb:1:in `<top (required)>'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `block in load_spec_files'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `each'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in `load_spec_files'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:97:in `setup'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:in `run'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in `run'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.0.4/exe/rspec:4:in `<top (required)>'
from /Users/user/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `load'
from /Users/user/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `<main>'
from /Users/user/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/user/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Here is my gemfile:
group :development do
gem 'rails-dev-tweaks'
gem 'quiet_assets'
gem 'pry'
gem 'pry-byebug'
gem 'hirb'
gem 'spring'
gem 'spring-commands-rspec'
end
group :development, :test do
gem 'rspec-rails', '~> 3.0.0'
gem 'factory_girl_rails'
end
group :test do
gem 'database_cleaner'
end
rails_helper.rb:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
end
spec_helper.rb:
RSpec.configure do |config|
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
expectations.syntax = :expect
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
mocks.syntax = :expect
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended.
mocks.verify_partial_doubles = true
end
end
my _spec file:
require 'rails_helper'
describe 'CampaignsManagement::CpaCalculator' do
let(:campaign) {
camp = FactoryGirl.build_stubbed(:campaign)
# campaign_histories_per_campaigns.times.each do |index|
# Factory.build(:campaign_history, value: index + 1, campaign_id: camp.id)
# end
camp
}
context "when there are some active campaigns" do
context "when the campaign have histories" do
let(:campaign_histories_per_campaigns) { 10 }
context 'when the campaign have histories created today' do
end
context 'when the campaign has only histories in the past (not generated today)' do
end
end
context "when the campaign is histories orphaned" do
let(:campaign_histories_per_campaigns) { 0 }
it "should not update redshift" do
campaign.campaign_histories.size.should.eq(0)
end
end
end
end
application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module RtbCampaignOptimization
class Application < Rails::Application
config.assets.enabled = false
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.autoload_paths << Rails.root.join('lib')
end
end
any ideas?
Thanks
Try to run:
rails generate rspec:install //which you must have already run
bundle install
And also check out this question and it's answers
According to the above, you need to add spork-rails to your Gemfile.
All the above-shared code snippets all look good.
i'm trying to load a new gem that i recently created, and don't have have any code yet, because when i tried to load just for test this error appeared.
My code:
My gem name is tracky.
tracky.gemspec
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'tracky/version'
Gem::Specification.new do |spec|
spec.name = "tracky"
spec.version = Tracky::VERSION
spec.authors = ["Matheus Mendes"]
spec.email = ["matheus.mendescf#gmail.com"]
spec.summary = %q{TODO: Write a short summary. Required.}
spec.description = %q{TODO: Write a longer description. Optional.}
spec.homepage = ""
spec.license = "MIT"
spec.files = [`git ls-files -z`.split("\x0")]
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
end
My folder:
http://postimg.org/image/ve7nlyja7/
Error:
irb(main):001:0> require_relative 'lib/tracky'
LoadError: cannot load such file -- tracky/version
from /home/matheus/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/matheus/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/matheus/Ruby/tracky/lib/tracky.rb:1:in `<top (required)>'
from (irb):1:in `require_relative'
from (irb):1
from /home/matheus/.rbenv/versions/2.2.2/bin/irb:11:in `<main>'
I'm using irb in the root of tracky
Inside the lib/tracky.rb file, change require "tracky/version" to require_relative "tracky/version".
This is because the version file is located relative to the lib/tracky.rb file. I would advise you reserve require for gem dependencies.
Check this answer for the difference between require and require_relative.
Late to the party but I guess it could help the next person. I came across this question while facing the same issue.
I want to test my RESTful resource in Rails:
require 'rubygems'
require 'activeresource'
class Event < ActiveResource::Base
self.site = "http://localhost:3000"
end
events = Event.find(:all)
puts events.map(&:name)
I have installed gem:
gem install activeresource
But when I launch my code I get the error message:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- activeresource (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from service.rb:2:in `<main>'
How can I require ActiveResource?
There is a typo in your require, the following is the correct one:
require 'active_resource'
With bunder you can do this just with
gem "activeresource", require: "active_resource"
Normally gems requires file with name equal to gem’s name, with gem "foo" :require => bar syntax you can specify different file to be included by default.
i think you can do it this way:
require 'rubygems'
gem 'activeresource'
require 'active_resource'
You can also specify which version of activeresource you want by
gem 'activeresource', '=3.0.7'
for example. Or you can omit this line completely, but this way it's cleaner... and it makes sure that you get the right version.
Hope this helps, NoICE