I'm developing a gem. There is a folder titled /spec and it contains 2 files:
#spec_helper.rb
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'my_gem'
#my_gem_spec.rb
describe MyGem do
it 'should have a version number' do
MyGem::VERSION.should_not be_nil
end
#............
end
Then I run it
rspec spec
/var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration.rb:491:in `add_formatter': Formatter 'specdoc' unknown - maybe you meant 'documentation' or 'progress'?. (ArgumentError)
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration_options.rb:30:in `block in configure'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration_options.rb:30:in `each'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/configuration_options.rb:30:in `configure'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/command_line.rb:21:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:80:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.12.2/lib/rspec/core/runner.rb:17:in `block in autorun'
What does it mean? How to get rid of it?
Here is the bundle's output
bundle install
Using rake (10.0.3)
Using diff-lcs (1.1.3)
Using my_gem (0.0.1) from source at .
Using rspec-core (2.12.2)
Using rspec-expectations (2.12.1)
Using rspec-mocks (2.12.1)
Using rspec (2.12.0)
Using bundler (1.3.0.pre.4)
Uninstall all previous versions of rspec and its dependencies.
gem uninstall rspec
gem uninstall rspec-core
gem uninstall rspec-mocks
gem uninstall rspec-expectations
Install the correct version of rspec in gem file install rspec.
group :development, :test do
gem 'rspec-rails', '~> 3.0.0'
end
see this answer
Related
I wrote a rake task to execute the berks package command on a Berksfile in a sub-directory:
task :cook do
`berks package ./cookbooks.tar.gz -b ./cookbook/Berksfile`
end
I've also tried these variations:
task :cook do
`.\\scripts\\berks_package.bat` # containing stuff
end
task :cook do
`C:\\opscode\\chefdk\\embedded\\bin\\ruby.exe "C:\\opscode\\chefdk\\bin\\berks" package ..\\cookbooks.tar.gz -b ..\\cookbook\\Berksfile`
end
No matter the way I execute berks, the task fails with the following error:
C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:434:in `version_conflict': Bundler could not find compatible versions for gem "nokogiri": (Bundler::VersionConflict)
In snapshot (Gemfile.lock):
nokogiri (1.6.5)
In Gemfile:
albacore (~> 2.0.0) x86-mingw32 depends on
nokogiri (~> 1.5) x86-mingw32
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:232:in `resolve_for_conflict'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:250:in `resolve_conflict'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:373:in `resolve'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:166:in `start'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/resolver.rb:129:in `resolve'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/definition.rb:193:in `resolve'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/definition.rb:132:in `specs'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/definition.rb:177:in `specs_for'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/definition.rb:166:in `requested_specs'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/environment.rb:18:in `requested_specs'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/runtime.rb:13:in `setup'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler.rb:122:in `setup'
from C:/tools/ruby213/lib/ruby/gems/2.1.0/gems/bundler-1.7.9/lib/bundler/setup.rb:17:in `<top (required)>'
from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
rake aborted!
Albacore::CommandFailedError: Command failed with status (1):
.\scripts\berks_package.bat
Executing berks package ./cookbooks.tar.gz -b ./cookbook/Berksfile from a command prompt works as does executing other normal system commands inside the task.
Gemfile:
source 'https://rubygems.org'
gem 'albacore', '~> 2.0.0'
gem 'semver2', '~> 3.4.0'
Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
albacore (2.0.16)
map (~> 6.5)
nokogiri (~> 1.5)
rake (~> 10)
semver2 (~> 3.4)
map (6.5.5)
mini_portile (0.6.1)
nokogiri (1.6.5-x64-mingw32)
mini_portile (~> 0.6.0)
rake (10.4.2)
semver2 (3.4.0)
PLATFORMS
x64-mingw32
DEPENDENCIES
albacore (~> 2.0.0)
semver2 (~> 3.4.0)
I figured out the problem as I wrote the question and stumbled upon new ideas.
The root problem was that the Ruby binary and gems installed with the ChefDK were conflicting with the system install of Ruby. Specifically, the rake task was executed under the system Ruby installation, but when berks was executed, it ran under the embedded ChefDK Ruby. I'm not clear on this next part, but it seems that the ChefDK Ruby was aware of the Gemfile and tried to resolve the dependencies itself, but because nokogiri cannot be resolved (i.e. built) by bundler on Windows without pain, it failed.
Here is what I did to resolve the issue:
Uninstalled the system Ruby
Added C:\opscode\chefdk\bin to the system PATH variable so I could run ruby, rake, gem, bundle, etc.
Ran gem install nokogiri (now executed under the ChefDK's Ruby)
Recreated the Gemfile.lock file by running bundle install
Surrounded the berks system call with a Bundler.with_clean_env block (this is key!)
Thanks to this question
The task now looks like:
task :cook do
Bundler.with_clean_env do
`berks package cookbooks.tar.gz -b .\\cookbook\\Berksfile`
end
end
I am having a hard time figure out the first lesson on Test-First Ruby (Alex Chaffee), I am running "rake" test and am getting errors that I am not supposed to receive.
I already tried doing the gem update --system and removing spaces as suggested in previous posts. None of this solved the problem.
Bellow are my specs and errors received.
I will appreciate any help.
ruby 1.9.3p545 (2014-02-24) [i386-mingw32]
C:\Users\Greice>gem list
*** LOCAL GEMS ***
activemodel (4.1.4)
activerecord (4.1.4)
activesupport (4.1.4)
arel (5.0.1.20140414130214)
bigdecimal (1.2.5, 1.1.0)
builder (3.2.2)
bundler (1.6.5)
diff-lcs (1.2.5)
feedtools (0.2.29)
hpricot (0.8.6)
i18n (0.6.11)
io-console (0.4.2, 0.3)
json (1.8.1, 1.5.5)
minitest (5.4.0, 2.5.1)
rake (10.3.2, 0.9.2.2)
rdoc (4.1.1, 3.9.5)
RedCloth (4.2.9 x86-mingw32)
rspec (3.0.0, 2.0.1)
rspec-core (3.0.3, 2.0.1)
rspec-expectations (3.0.3, 2.0.1)
rspec-mocks (3.0.3, 2.0.1)
rspec-support (3.0.3)
rubygems-update (2.4.1)
sunlight-congress (1.1.0)
thread_safe (0.3.4)
tzinfo (1.2.1)
uuidtools (2.1.4)
C:\Users\Greice\Desktop\test-first-ruby-master>cd 00_hello
C:\Users\Greice\Desktop\test-first-ruby-master\00_hello>rake
(in C:/Users/Greice/Desktop/test-first-ruby-master)
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/option_parse
r.rb:18:in `parse!': invalid option: --warnings (OptionParser::InvalidOption)
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core
/option_parser.rb:4:in `parse!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core
/configuration_options.rb:78:in `parse_options_file'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core
/configuration_options.rb:74:in `parse_global_options'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core
/configuration_options.rb:48:in `parse_options'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core
/runner.rb:41:in `run'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core
/runner.rb:10:in `block in autorun'
rake aborted!
ruby -S bundle exec rspec -IC:/Users/Greice/Desktop/test-first-ruby-master/00_he
llo -IC:/Users/Greice/Desktop/test-first-ruby-master/00_hello/solution -f docume
ntation -r ./rspec_config "C:/Users/Greice/Desktop/test-first-ruby-master/00_hel
lo/hello_spec.rb" failed
Tasks: TOP => default => spec
(See full trace by running task with --trace)
Rakefile
# This Rakefile has all the right settings to run the tests inside each lab
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.gsub(' ', '\ ')
task.pattern = "#{lab}/*_spec.rb"
task.rspec_opts = [ "-I#{lab}", "-I#{lab}/solution", '-f documentation', '-r ./rspec_config']
task.verbose = false
end
rspec_config.rb
RSpec.configure do |c|
c.fail_fast = true
c.color = true
end
I've seen this before when --warnings was an option in the .rspec file.
Try removing the --warnings line from your .rspec or rspec_config file.
Your help would be MUCH appreciated. I am new to programming and want am trying to start alexch's Learn_Ruby, but am stuck on the very first lesson: 00_hello.
I am running "rake" test am am getting weird errors:
Justins-MacBook-Pro:00_hello Justin$ rake
(in /Users/Justin/Desktop/learn_ruby-master)
rake aborted!
undefined method `gem' for main:Object
/Users/Justin/Desktop/learn_ruby-master/Rakefile:2
(See full trace by running task with --trace)
I'm just following the instructions from the course: https://github.com/alexch/learn_ruby/blob/master/index.html
here are my specs:
ruby 1.8.7
rspec 2.12
gem 1.8.25
anything thing else i'm missing??
Your Help is MUCH appreciate.
here is the gem list:
Justins-MacBook-Pro:00_hello Justin$ gem list
*** LOCAL GEMS ***
activemodel (3.2.11)
activerecord (3.2.11)
activesupport (3.2.11)
arel (3.0.2)
builder (3.1.4, 3.0.4)
diff-lcs (1.2.0, 1.1.3)
i18n (0.6.1)
multi_json (1.5.0)
rspec (2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
rspec-mocks (2.12.2)
rubygems-update (1.8.25)
tzinfo (0.3.35)
uuidtools (2.1.3)
First update rubygems by following command:
gem update --system
That should solve it.
If not then try removing the following line from the rakefile
gem 'rspec', '~>2'
So I'm working on a gem... I type bundle, and it installs rspec 2.0.1 which, as I'm sure you'll understand, is simply unacceptable in this day and age of rspec 2.12.2 .
I'd be OK with it, except when I run rake spec...
% rake spec
/home/alg/.rvm/rubies/ruby-1.9.3-p374/bin/ruby -S bundle exec rspec "./spec/file_comparisons_spec.rb" "./spec/monitor_spec.rb" "./spec/pipboy_spec.rb"
/home/alg/Documents/Code/pipboy/spec/spec_helper.rb:8:in `block in <top (required)>': undefined method `treat_symbols_as_metadata_keys_with_true_values=' for #<RSpec::Core::Configuration:0x9c99a74> (NoMethodError)
from /home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core.rb:67:in `configure'
from /home/alg/Documents/Code/pipboy/spec/spec_helper.rb:7:in `<top (required)>'
from /home/alg/Documents/Code/pipboy/spec/file_comparisons_spec.rb:1:in `require'
from /home/alg/Documents/Code/pipboy/spec/file_comparisons_spec.rb:1:in `<top (required)>'
from /home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load'
from /home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `block in load_spec_files'
from /home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map'
from /home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files'
from /home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run'
from /home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run'
from /home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
ruby -S bundle exec rspec "./spec/file_comparisons_spec.rb" "./spec/monitor_spec.rb" "./spec/pipboy_spec.rb" failed
/home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/rake_task.rb:117:in `rescue in block (2 levels) in initialize'
/home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/rake_task.rb:113:in `block (2 levels) in initialize'
/home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/gems/rspec-core-2.0.1/lib/rspec/core/rake_task.rb:109:in `block in initialize'
/home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/bin/ruby_noexec_wrapper:14:in `eval'
/home/alg/.rvm/gems/ruby-1.9.3-p374#pipboy/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => spec
(See full trace by running task with --trace)
So here's the bits which I think are important, even though I can't find anything wrong with them:
=> Rakefile
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format progress"
end
=> Gemfile
source :rubygems
# Specify your gem's dependencies in pipboy.gemspec
gemspec
=> gemspec
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'pipboy/version'
Gem::Specification.new do |gem|
gem.files = `git ls-files`.split($/)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'cucumber'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rdoc'
end
And, with no Gemfile.lock, the result of calling bundle...
% bundle
Fetching gem metadata from http://rubygems.org/.........
Fetching gem metadata from http://rubygems.org/..
Using rake (10.0.3)
Using builder (3.1.4)
Using diff-lcs (1.2.0)
Using json (1.7.6)
Using gherkin (2.11.5)
Using cucumber (1.2.1)
Using pipboy (0.0.1) from source at /home/alg/Documents/Code/pipboy
Using rdoc (3.12)
Using rspec-core (2.0.1)
Using rspec-expectations (2.0.1)
Using rspec-mocks (2.0.1)
Using rspec (2.0.1)
Using bundler (1.2.3)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
=> Gemfile.lock after the fact
PATH
remote: .
specs:
pipboy (0.0.1)
GEM
remote: http://rubygems.org/
specs:
builder (3.1.4)
cucumber (1.2.1)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
gherkin (~> 2.11.0)
json (>= 1.4.6)
diff-lcs (1.2.0)
gherkin (2.11.5)
json (>= 1.4.6)
json (1.7.6)
rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
rspec (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
rspec-mocks (~> 2.0.1)
rspec-core (2.0.1)
rspec-expectations (2.0.1)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
PLATFORMS
ruby
DEPENDENCIES
cucumber
pipboy!
rake
rdoc
rspec
The trick, it seems, was to do this.
gem.add_development_dependency 'rspec', '>= 2.12.0'
rspec-core, used by rspec, is at 2.12.2 -- and I mistakenly thought that these sub-gems would minor up at the same time as the meta-gem.
Then again, I have -no idea- why it was downloading rspec 2.0.1 and not 2.12.0 ...
I was trying to learn about the Sinatra ruby framework by following this tutorial:
http://net.tutsplus.com/tutorials/ruby/singing-with-sinatra-the-recall-app-2/
however, after running the gem install and writing a simple sinatra server in test.rb like so:
require 'sinatra'
require 'datamapper'
get '/' do
"Hello, World!"
end
but when I run the command ruby test.rb, I get the following error:
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- datamapper (LoadError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from datamapper_test.rb:2:in `<main>'
glenn#ubuntu:~/Dropbox/Repositories/sandbox/sinatra$ ruby datamapper_test.rb
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- datamapper (LoadError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test.rb:3:in `<main>'
it seems as though it cannot find the datamapper gem. how can I fix this?
EDIT: using ruby 1.9.2
EDIT (again): (parital) output from gem list:
data_mapper (1.2.0)
data_objects (0.10.8)
datamapper (1.2.0)
devise (1.4.5)
directory_watcher (1.4.0)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.0)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-serializer (1.2.1)
dm-sqlite-adapter (1.2.0)
d m-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.1)
dm-validations (1.2.0)
do_sqlite3 (0.10.8)
sinatra (1.3.2, 1.2.6)
sqlite3 (1.3.5, 1.3.4)
sqlite3-ruby (1.3.3)
You need to require 'data_mapper', not datamapper.
Note there is a datamapper gem as well as a data_mapper gem, but they are the same thing, just different names. You need use data_mapper as the library name in both of them.
As far as I can tell datamapper is a straight copy of data_mapper:
$ diff -r data_mapper-1.2.0/ datamapper-1.2.0/
diff -r data_mapper-1.2.0/Rakefile datamapper-1.2.0/Rakefile
21c21
< GEM_NAME = 'data_mapper'
---
> GEM_NAME = 'datamapper'
gem install datamapper in your terminal might help :)
But you will also need a database and an adapter and you will want to use the gem somehow. Good luck and have fun with dm + sinatra!