[✔] Running puppet validators ...
├── [✔] Checking Puppet manifest syntax (**/*.pp).
└── [✔] Checking Puppet manifest style (**/*.pp).
✖] Running ruby validators ...
└── [✖] Checking Ruby code style (**/**.rb).
Pdk validate fails
Pdk validate fails
Run your command with "-d" option which is debug so that it will show what errors we are able to see in ruby validator.
pdk validate -d
Related
I have been trying to run my cookbooks from many hours and gone through multiple questions regarding the same but still couldn't manage to make it work.
sudo chef-solo -c solo.rb -j node.json -o main::default;
I'm running the above command inside my cookbooks folder which contains other cookbooks like apt, git, etc.
And, inside cookbooks/main/recipe/default.rb I'm including include_recipe "apt".
Every time, I run the command I get the following error:
Cookbook apt not found. If you're loading apt from another cookbook,
make sure you configure the dependency in your metadata
So I added depends "apt" inside my cookbooks/main/metadata.rb. But now I'm getting this error:
Cookbook depends on itself in cookbook apt, please remove this
unnecessary self-dependency
Without more information it's difficult to extrapolate where the problem may lie. Here's an example of how you should theoretically be laying out your cookbooks/files, though:
All cookbooks you're writing go in <dir>/cookbooks/.
All vendored cookbooks (e.g. apt) go in <dir>/vendor/.
So your structure, at a very stripped down level, might look something like this:
.
├── cookbooks
│ └── main
│ ├── metadata.rb
│ └── recipes
├── solo.rb
└── vendor
└── apt
├── metadata.rb
└── recipes
Now lets take a look at some individual files:
The default recipe of your main cookbook:
# cookbooks/main/recipes/default.rb
include_recipe 'apt'
And your main cookbook's metadata file:
# cookbooks/main/metadata.rb
name 'main'
...
depends 'apt'
Note that the apt cookbook resides in vendor/. Anything here should be from third parties and you should not modify.
From here, you just need to ensure your solo.rb properly references both cookbook directories for the cookbook_path attribute:
# solo.rb
...
cookbook_path ['cookbooks/', 'vendor/']
...
A second answer because this was diagnosed on Slack, themain cookbook had name "apt" in its metadata which made the error message confusing.
So as a somewhat unrelated answer: there is a very low chance you actually need that apt::default recipe. We've moved most of the stuff that cookbook in to Chef core. If you just want to run an apt-get update, use the apt_update resource.
I'm trying to write a Foodcritic rule which verifies only Private Supermarkets are listed in a Berksfile. Are the Berksfile source URLs included in the Ruby AST?
No, but you could use RuboCop. Foodcritic is only for cookbook stuffs specifically.
I'm working on a Ruby gem and I'm getting an odd error. I have previously released this gem without too much trouble. I added some methods / refactored some code and wanted to release a subsequent version (from 1.1 to 1.2).
For reference, the name of the gem is Intervallum, (the word 'interval' in Latin).
I'm getting a 'require' error that's been stumping me.
The folder tree is:
.
├── Gemfile
├── LICENSE
├── README.md
├── intervallum-[version].gem
├── intervallum.gemspec
└── lib
├── intervallum
│ ├── module.scroll.rb
│ └── module.spell.rb
└── intervallum.rb
In lib/intervallum.rb I tried Dir.glob, Dir['./lib/intervallum/*'] and require '../intervallum/lib/intervallum/module.spell.rb' and what happens for each one is:
Locally, after gem build intervallum.gemspec and gem install intervallum-[version].gem, I boot up irb and require intervallum and it works fine.
push to RubyGems
remove the local copy
install from RG
load up in irb I get load errors or it cannot find class of a helper class
I'm not sure why this keeps occurring, or if there's something that I'm missing as to why this keeps occurring but any advice would be much appreciated.
The problem is that you are not including those files in the gem when it gets packaged. Your gemspec specifies that only the lib/intervallum.rb file will be included in the gem:
s.files = ["./lib/intervallum.rb"]
Change that line to include all files in lib. It's also a good idea to include the gemspec.
s.files = Dir['lib/**/*', 'intervallum.gemspec']
I am trying to run rspec only for Ruby (not Rails), for a simple Ruby file. I'm following Tut+ TDD Testing with Ruby.
I have a competition directory with a lib folder and spec folder.
├── lib
│ ├── competition.rb
│ └── team.rb
└── spec
└── competition_spec.rb
When I run rspec, I got this error. I could've sworn the rspec work before. I don't know what happened.
competition :> rspec spec
/Users/akh88/.rvm/gems/ruby-1.9.3-p547/gems/rspec-core-> 3.0.2/lib/rspec/core/formatters.rb:167:in `find_formatter': Formatter 'nested' unknown - maybe you meant 'documentation' or 'progress'?. (ArgumentError)
My competition_spec.rb
require_relative "../lib/competiiton.rb"
require_relative "../lib/team.rb"
describe Competition do
let(:competition) {Competition.new}
let(:team) {Team.new}
context "having no questions" do
before { competition.questions = [] }
it "doesn't accept any teams" do
expect do
team.enter_competition(competition)
end.to raise_error Competition::Closed
end
end
end
My rvm default Ruby version is 1.9.1 on Mac OSX 10.9.4.
The nested formatter was used in RSpec 1. This was renamed documentation in RSpec 2.
Maybe you have specified nested on the command line or in a .rspec file? Then you need to specify --format documentation instead.
Have you set config.formatter = nested somewhere, probably your spec_helper.rb file? Remove it.
You could have updated the RSpec gem from v1 (the command to run tests changed from spec to rspec though so that's hard to miss). You can check versions with gem list rspec.
Alternatively, you could be missing the load of a custom formatter you happened to call nested.
My .rspec file only had
--color
and I was still getting this error.
I explicitly set it to
--format documentation --color
And now it works.
I'm after an overview/clarification of the ideal project structure for a ruby (non-rails/merb/etc) project. I'm guessing it follows
app/
bin/ #Files for command-line execution
lib/
appname.rb
appname/ #Classes and so on
Rakefile #Running tests
README
test,spec,features/ #Whichever means of testing you go for
appname.gemspec #If it's a gem
Have I got something wrong? What parts have I missed out?
I think that is pretty much spot on. By default, Rubygems will add the lib directory to the loadpath, but you can push any directory you want onto that using the $: variable. i.e.
$:.push File.expand_path(File.dirname(__FILE__) + '/../surfcompstuff')
That means when you have say, surfer.rb in that dir, you can require "surfer" anywhere and the file will be found.
Also, as a convention, classes and singletons get a file and modules get a directory. For instance, if you had the LolCatz module and the LolCatz::Moar class that would look like:
lib/
appname.rb
lolcatz/
moar.rb
That is why there is an lib/appname folder because most libraries are in the appname namespace.
Additionally, if you try running the command newgem --simple [projectname] that'll quickly generate a scaffold for you with just the bare essentials for a Ruby project (and by extension a Ruby Gem). There are other tools which do this, I know, but newgem is pretty common. I usually get rid of the TODO file and all the script stuff.
See the following example from http://guides.rubygems.org/what-is-a-gem/
% tree freewill
freewill/
├── bin/
│ └── freewill
├── lib/
│ └── freewill.rb
├── test/
│ └── test_freewill.rb
├── README
├── Rakefile
└── freewill.gemspec
I attempt to mimic the Rails project structure because my team, which usually deals with Rails, will understand the structure better than another configuration. Convention over Configuration - bleeding over from Rails.
If you use bundler, running this command bundle gem app_name will give you the same directory structure.
If you want to use rspec instead of unit tests you can then run this command rspec --init
(Just make sure you cd app_name first)