getting error on running cmd in windows Please help me what to do: here is rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for
example lib/tasks/capistrano.rake, and they will automatically be available to
Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
and here is the cmd window
c:\Fedena>rake db:create --trace
(in c:/Fedena)
rake aborted!
c:/Fedena/Rakefile:3: syntax error, unexpected kAND
...lib/tasks/capistrano.rake, and they will automatically be av...
^
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `load'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2017:in `load_rakefile'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2000:in `run'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
C:/Ruby187/bin/rake:23:in `load'
C:/Ruby187/bin/rake:23
Shouldn't this part be commented out?
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for
#example lib/tasks/capistrano.rake, and they will automatically be available to
#Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
Looks like it's not commented out and ruby is trying to run it as code
My installation is successful. Below is my rake file content:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
Copy and paste the above content in your rake file and try again
Related
I'm trying to deploy a simple Ruby app to Heroku. I keep getting this error in the release logs, which look like this:
rake aborted!
NameError: uninitialized constant Dotenv
/app/config/environment.rb:5:in `<top (required)>'
/app/Rakefile:3:in `require_relative'
/app/Rakefile:3:in `<top (required)>'
/app/vendor/bundle/ruby/2.7.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli/exec.rb:63:in `load'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli/exec.rb:63:in `kernel_load'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli/exec.rb:28:in `run'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli.rb:474:in `exec'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli.rb:30:in `dispatch'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/cli.rb:24:in `start'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/exe/bundle:49:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.7.0/gems/bundler-2.2.21/exe/bundle:37:in `<top (required)>'
/app/vendor/bundle/bin/bundle:113:in `load'
/app/vendor/bundle/bin/bundle:113:in `<main>'
(See full trace by running task with --trace)
I've googled this a bunch and tried every suggestion, but I can't seem to fix it. For reference, here's my Gemfile:
source 'http://rubygems.org'
gem 'sinatra'
gem 'activerecord', "< 6", :require => 'active_record'
gem 'sinatra-activerecord', :require => 'sinatra/activerecord'
gem 'rake'
gem 'require_all'
gem 'thin'
gem 'bcrypt'
gem 'sinatra-flash'
gem 'rails_12factor'
gem 'foreman'
group :development, :test do
gem 'sqlite3', '<1.4'
gem 'shotgun'
gem 'tux'
gem 'pry'
gem 'session_secret_generator'
gem 'dotenv'
end
group :production do
gem 'pg', '0.20'
end
group :test do
gem 'rspec'
gem 'capybara'
gem 'rack-test'
gem 'database_cleaner', git: 'https://github.com/bmabey/database_cleaner.git'
end
and here's my config/environment.rb:
ENV['SINATRA_ENV'] ||= "development"
require 'bundler/setup'
Bundler.require(:default, ENV['SINATRA_ENV'])
Dotenv.load if ENV['SINATRA_ENV'] == "development"
set :database_file, "./database.yml"
require './app/controllers/application_controller'
require_all 'app'
Thanks!
Maybe you are missing: require 'dotenv' before trying Dotenv.load?
Problems
Note that your Gemfile places dotenv into your :development and :test groups. It is not available in your default or :production groups, so you are unlikely to be getting your gem loaded via Bundler.require as currently configured.
Suggested Solutions
My suggestions include:
ensure you're using APP_ENV to set your Sinatra environment, not something custom like SINATRA_ENV, which may or may not doing what you think on Heroku
use Heroku's config-vars rather than dotenv in production
note that Heroku probably defaults to excluding :development, :test, and :ci groups when running bundle install, but you can configure this behavior via environment variables
move dotenv to your default group (if you really need it everywhere)
if you don't move dotenv into the default group, you need to modify your Bundler.require to add the correct group containing the dotenv gem into the list of groups to require (provided Bundler has installed that group)
You may have other issues as well, but these are the ones that jumped out at me from the code and errors you provided.
I have a Rakefile that requires some Bundler tasks
Rakefile:
require "bundler/gem_tasks"
require "rake/testtask"
.
.
.
And a minitest file that loads the Rakefile so I can test my tasks:
load File.expand_path("../../Rakefile", __FILE__)
require 'minitest/autorun'
require 'rake'
class RakeTest < Minitest::Test
def test_rake_just_works
assert_output("Running some_namespace:some_task...\n") do
Rake::Task["some_namespace:some_task"].invoke
end
end
end
The problem is Sublime doesn't like the require "bundler/gem_tasks" and gives the following error:
/Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/gem_helper.rb:30:in `initialize': Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it. (RuntimeError)
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/gem_helper.rb:14:in `new'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/gem_helper.rb:14:in `install_tasks'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/gem_tasks.rb:6:in `<top (required)>'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `require'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
from /Users/max/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from /Users/max/Dropbox/work/src/github.com/mbigras/some_gem/Rakefile:1:in `<top (required)>'
from /Users/max/Dropbox/work/src/github.com/mbigras/some_gem/test/rake_test.rb:1:in `load'
from /Users/max/Dropbox/work/src/github.com/mbigras/some_gem/test/rake_test.rb:1:in `<main>'
[Finished in 0.5s with exit code 1]
[shell_cmd: /Users/max/.rbenv/shims/ruby "/Users/max/Dropbox/work/src/github.com/mbigras/some_gem/test/rake_test.rb"]
[dir: /Users/max/Dropbox/work/src/github.com/mbigras/some_gem/test]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
There is no error if I run ruby test/rake_test.rb from the command-line (leaving the require statement as is):
➜ some_gem master ✗ ruby test/rake_test.rb
Run options: --seed 45743
# Running:
.
Finished in 0.002035s, 491.4005 runs/s, 491.4005 assertions/s.
1 runs, 1 assertions, 0 failures, 0 errors, 0 skips
Sublime does work if I remove the require statement, but then I lose all my Bundler rake tasks.
I found an issue that references this problem in the context of using the Bundler tasks for multiple gems. Seems different than my use-case but I tried the solution anyways and it doesn't work, and gives the same error:
Rakefile:
require "bundler/gem_tasks"
Bundler::GemHelper.install_tasks :name => "some_gem"
require "rake/testtask"
I think it might have to do with the path for Sublimes build system. I tried using my rbenv ruby shim but it also didn't work:
{
"shell_cmd": "/Users/max/.rbenv/shims/ruby \"$file\"",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}
I have been able to run my app locally using sinatra, but the moment I push it to heroku, I keep getting this error:
/app/lib/initializers/twitter.rb:1:in `require': cannot load such file -- Twitter
I authorize myself using the twitter gem in a initializer file.
init.rb
APP_ROOT = File.dirname(__FILE__)
require 'sinatra'
require 'json'
require File.join(APP_ROOT,"lib","bot")
require './lib/bot'
get '/' do
File.read(File.join( APP_ROOT, 'index.html'))
end
lib/initializers/twitter.rb
require 'Twitter'
$client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV["CONSUMER_KEY"]
config.consumer_secret = ENV["CONSUMER_SECRET"]
config.access_token = ENV["ACCESS_TOKEN"]
config.access_token_secret = ENV["ACCESS_TOKEN_SECRET"]
end
Gemfile
ruby '2.3.1'
source 'https://rubygems.org'
gem 'rack'
gem 'twitter'
gem 'sinatra'
gem "sinatra-activerecord"
gem 'thin'
gem 'json'
config.ru
require './lib/initializers/secrets'
require './lib/initializers/twitter'
require './init'
run Sinatra::Application
Even for rake task I keep getting the below error in my local:
LoadError: cannot load such file -- active_record/railties/databases.rake
/Users/sahil/.rvm/gems/ruby-2.3.1/gems/sinatra-activerecord-2.0.11/lib/sinatra/activerecord/rake.rb:1:in `load'
/Users/sahil/.rvm/gems/ruby-2.3.1/gems/sinatra-activerecord-2.0.11/lib/sinatra/activerecord/rake.rb:1:in `<top (required)>'
/Users/sahil/Documents/work/practice/twitter_bot/Rakefile:2:in `<top (required)>'
/Users/sahil/.rvm/gems/ruby-2.3.1/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/Users/sahil/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/Users/sahil/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
LoadError: cannot load such file -- sinatra/activerecord/rake
/Users/sahil/Documents/work/practice/twitter_bot/Rakefile:2:in `<top (required)>'
/Users/sahil/.rvm/gems/ruby-2.3.1/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/Users/sahil/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/Users/sahil/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
Rakefile
require "./lib/bot"
require "sinatra/activerecord/rake"
Dir.glob('lib/tasks/*.rake').each { |r| load r}
lib/tasks/scheduler.rake
require './../bot'
desc "This task is called by the Heroku scheduler add-on"
task :fav_tweets => :environment do
bot = Bot.new
end
How can I run a scheduler in my local first so that I can add the same to heroku?
You appear to be running:
require 'Twitter'
Note the capital T. Does it work if you run instead:
require 'twitter'
It looks like your local machine is running OS X, which typically uses a case-insensitive HFS+ filesystem.
Heroku runs on Linux systems, which typically use case-sensitive filesystems.
I'm working on my 'gravaty gem (https://rubygems.org/gems/gravaty) and I have some configuration issues working on command line and RubyMine IDE at the same time.
I'm using JetBrains' RubyMine IDE and sometimes also command like through my Rakefile. If, from project main dir, I wrote rake test via command line, all tests work properly (they run and provide results, one test is not passing but that's another story...) while, if I run them from the IDE (with a Run/Debug configuration) I have this message:
1. B:/Programmi/gravaty/test/gravaty/locales/test_locales.rb:1
Fail to load: B:/Programmi/gravaty/test/gravaty/parsers/test_avatar.rb:1
Exception message: cannot load such file -- gravaty/test_parsable_duck_type
["B:/Programmi/gravaty/test/test_helper.rb:34:in `require'", "B:/Programmi/gravaty/test/test_helper.rb:34:in `<top (required)>'", "B:/Programmi/gravaty/test/gravaty/parsers/test_avatar.rb:15:in `require_relative'", "B:/Programmi/gravaty/test/gravaty/parsers/test_avatar.rb:15:in `<top (required)>'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `require'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:51:in `block in require_all_test_scripts'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `each'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:44:in `require_all_test_scripts'", "C:/Program Files (x86)/JetBrains/RubyMine 6.0.3/rb/testing/runner/tunit_or_minitest_in_folder_runner.rb:138:in `<top (required)>'", "-e:1:in `load'", "-e:1:in `<main>'"]
and so on (one for each test file) with all its stacktrace.
In order to easily configure the correct (?) require environment, I put the statements
lib_dir = File.dirname(__FILE__) '/../lib'
$:.unshift lib_dir unless $:.include?(lib_dir)
at the beginning of my test_helper.rb file and it seems working from the command line, but the IDE does not appreciate. Considering this statements in the test_helper.rb,
require 'minitest/autorun'
require 'minitest/spec'
lib_dir = File.dirname(__FILE__) + '/../lib'
$:.unshift lib_dir unless $:.include?(lib_dir)
require 'gravaty'
require 'gravaty/constants'
require 'gravaty/parsers/avatar'
require 'gravaty/parsers/callback'
require 'gravaty/parsers/default'
require 'gravaty/parsers/force'
require 'gravaty/parsers/format'
require 'gravaty/parsers/pixelsize'
require 'gravaty/parsers/rating'
require 'gravaty/parsers/secure'
require 'gravaty/parsers/type'
require 'gravaty/test_parsable_duck_type'
the IDE underlines all the require 'gravaty/ statements saying Unresolved Ruby reference. I've added my lib directory to the Load Path preference of the IDE, but nothing changes.
Is there a way to make it work in both environments? Should I "carve" the full require path in each file and in each require statement?
I've found the solution: instead of using the Test::Unit/Shoulda/Minitest Run/Debug configuration, I can just run the tests through a simple Rake task Run/Debug configuration.
Here is my project structure:
/app
--/lib
----/porter.rb
--/spec
----/porter_spec.rb
In file porter_spec.rb i have include directive:
require '../lib/porter'
Now I'm trying to run the test:
cd app
rspec
and get the error:
C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- ../lib/porter (LoadError)
from C:/Ruby193/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Dropbox/development/myprojects/lj-parser/spec/porter_spec.rb:3:in `<top (required)>'
How can I require file on lib folder?
Apparently, your current dir is not what you think it is.
You should use require_relative (ruby 1.9+):
require_relative '../lib/porter'
In ruby1.9, you can use:
require_relative '../lib/porter'
In ruby1.8 or higher, you can use:
require File.expand_path("../lib/porter", __FILE__)