Create hanami project? - ruby

With hanami 2.0.1 and ruby version 3.0.2...
When create hanami new bookshelf.I got this error..
Created bookshelf/
-> Within bookshelf/
Created .env
Created README.md
Created Gemfile
Created Rakefile
Created config.ru
Created config/app.rb
Created config/settings.rb
Created config/routes.rb
Created config/puma.rb
Created lib/tasks/.keep
Created lib/bookshelf/types.rb
Created app/actions/.keep
Created app/action.rb
Running Bundler install...
`bundle install' failed
"install: unknown option -- jobs=2\nTry 'install --help' for more information."
I use bundle install but still ................
cd bookshelf and run bundle install,It's worked
but when
bundle exec hanami server
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.3.26/lib/bundler/rubygems_integration.rb:308:in `block in replace_bin_path': can't find executable guard for gem guard. guard is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bundler-2.3.26/lib/bundler/rubygems_integration.rb:336:in `block in replace_bin_path'
from C:/Ruby30-x64/bin/guard:23:in `<main>'
Add gem 'guard' into Gemfile.
No Guardfile exists at Guardfile. (Guard::Guardfile::Evaluator::NoCustomGuardfile)

From the root of your app, run bundle exec hanami install.

Related

The git source is not yet checked out when running Docker

I'm currently facing an error when trying to use a gem from GitHub. I have the following in my Gemfile:
# Gemfile
source 'https://rubygems.org'
ruby '2.3.1'
gem 'sinatra'
gem 'rack'
gem 'puma'
group :development do
gem 'byebug'
gem 'rack-test'
gem 'rerun', github: 'alexch/rerun', branch: 'master'
end
When I run bundle install from Dockerfile it works with a message like:
...
Installing sinatra 1.4.6
Installing listen 3.1.5 (was 3.0.6)
Using rerun 0.11.0 from git://github.com/alexch/rerun.git (at master#3e4c486)
Bundle complete! 6 Gemfile dependencies, 14 gems now installed.
...
However, when I go to start the container I get:
The git source git://github.com/alexch/rerun.git is not yet checked out. Please run `bundle install` before trying to start your application
I've seen similar issues but not related to Docker.
Turns out I was able to find the issue. The problem was related to my Gemfile being used to build the Docker image.
I had not locally run a bundle install command which led to the Gemfile.lock not being updated. Once I ran the command the following was added to my Gemfile.lock:
## -1,14 +1,20 ##
+GIT
+ remote: git://github.com/alexch/rerun.git
+ revision: 3e4c486304be406cb86180ef70ec24e9ae055ce4
+ branch: master
+ specs:
+ rerun (0.11.0)
+ listen (~> 3.0)
Turns out that was all I needed. Once I had the updated file, rebuilt the image and ran the container everything worked as expected with bundle exec rerun. So the catch was that I was using the Gemfile.lock to help with caching / version locking but failed to keep it updated with my Gemfile.
In case anyone is interested there's an alternative.
During image creation, if your dockerfile runs bundle install it will generate a Gemfile.lock in the container. You can use docker run to get the contents, e.g.
docker run web cat Gemfile.lock
You can copy the contents and save a Gemfile.lock to your project directory.
Worked to me:
docker-compose run web bundle install

Executing chef test from a rakefile

I have some chef unit tests that I can run via the command : chef exec rspec
However, I am trying to run these from TeamCity and I am using a rakefile. When I try to execute the rakefile the require 'chefspec' line in the test file causes an error "cannot load such file -- chefspec (LoadError)"
I know chefspec is installed. I am new to Ruby, chefspec, rspec. I know there is mention of a gemspec file and I have tried to create one in the directory where I can run the command chef exec rspec to execute the test. However, when I try to run bundle install I get the error Could not locate Gemfile or .bundle/ directory. Is there a default location of a gemfile when you install ruby? I am pretty lost at this point.
C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire': cannot load such file -- chefspec (LoadErr
or)
from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require'
from D:/../spec/octopus_tentacle_spec.rb:1:in'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in load'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:inblock in load_
spec_files'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in each'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:inload_spec_file
s'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in setup'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:inrun'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in run'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:ininvoke'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/exe/rspec:4:in <top (required)>'
from C:/Ruby22/bin/rspec:23:inload'
from C:/Ruby22/bin/rspec:23:in <main>'
The gemspec files are normally used when you are creating a Ruby gem, and contains the metadata about the Gem you are creating.
when you use bundle install it requires a Gemfile in the directory. The Gemfile works as a manifest file for the gems required for the project in the directory. It is possible that chef exec is looking for this file and will only work with gems specified here.
Try creating a Gemfile with the content
source 'https://rubygems.org'
gem 'rspec'
gem 'chefspec'
you should list other gems you are using in the file.
and then run bundle install

Using rspec with a local gem

I am using a local gem (on my machine) with another application that is a command line app.
I have something like this in the gemfile to refer to the local gem:
gem 'mygem', :path => '/Users/devmachine/Projects/mygem'
When I run bundle console I am able to use the gem and all is well. However, whenever I run my test suite (rspec) I get the following message:
ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mygem (LoadError)
I'm confused. Any ideas?
You need to run:
bundle exec rspec
If you are not using the bundle evironment rspec won't know what you put in your Gemfile and just use the Gems it finds installed.

Make ruby script use local gems, instead of common

I'm deploying my rails project to production server. There is only 1.9.3 version of ruby (I developed on 2.1.2) so there is few compatibility problems in gems versions. More over, I downloaded one of gems to vendor/gem_name and made necessary fixes in its sources, so I need to use exactly my version of that gem and, as you understand, It's not possible to update it.
in Gemfile
require 'gem_name', :path => 'vendor/gem_name'
So after cloning project to server I run
bundle install --path vendor/bundle
and it created bundle directory in vendor folder with gems versions, needed to me, inside it.
After that I tried to run fetching script to fill db with some data by command
ruby *_fetch.rb
inside *_fetch.rb:
require 'gem_name'
And it fails with error
You have already activated gem_name older_version, but your Gemfile requires
gem_name newest_version. Using bundle exec may solve this. (Gem::LoadError)
from /usr/local/rvm/gems/ruby-1.9.3-p374/gems/bundler-1.3.5/lib/bundler/runtime.rb:19:in `setup'
So how could I specify script to require my edited local gem?
Run it with bundle exec That's exactly what bundle exec is for.

Bundle install runs from incorrect directory

I'm building a simple thor based generator for some internal projects, and can't seem to get bundle install running from the correct directory.
As I run the new [APP_NAME] function, it should create the directories and files, then run bundle install to install the gems required for the application.
The source of the generator function:
def create
puts "Creating application #{name}"
directory 'application', "#{name}"
Dir.chdir("#{Dir.pwd}/#{name}") do
puts `bundle install`
end
end
And the console output from running the command that calls this create method:
$ bundle exec bin/my_gem new test_app
Creating application test_app
create test_app
create test_app/Gemfile
create test_app/Guardfile
create test_app/README.md
create test_app/app/controllers
create test_app/app/helpers
create test_app/app/models
create test_app/app/views
Using thor (0.14.6)
Using my_gem (0.0.1)
Using bundler (1.1.3)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
As you can see, it is running bundle install but it's running it in my current directory (thor, bundler, my_gem), as opposed to the test_app directory (guard, guard-coffeescript, guard-less, and others) .
Running other commands such as ls or pwd give the expected results:
Gemfile
Guardfile
README.md
app
and
/Users/davidlumley/Development/Gems/my_gem/test_app
Not sure if it makes any difference, but I use RVM for managing my rubies.
Sounds like your app is already using bundler and you have a bundler-inside-bundler problem. Try this:
Bundler.with_clean_env do
puts `bundle install`
end
I'm guessing what's happening is that your outer bundler sets the BUNDLE_GEMFILE env variable to your app's Gemfile, and then your inner bundler ends up inheriting it.
Please try this i will sure helps you.
rvm gemset create app_name
rvm use ruby-1.9.2#app_name
Ruby version what else you used.
then install bundler gem
gem install bundler.
Then bundle install and run server..

Resources