I've been trying to get started with mutation testing for our rails app, but haven't been able to get it working - has anyone managed to set this up?
Here's what I've tried so far:
mutant -I app/models -r foo "Foo#bar" foo_spec.rb
.../trunk/app/models/foo.rb:24:in `<top (required)>': uninitialized constant ActiveRecord (NameError)
I've also tried loading the activerecord gem directly using -I, the gem is already installed in the current rvm gemset - I've got a feeling that this'll involve some more complete setup to use the database.yml, unfortunately I can't seem to find anyone who has done this already.
Disclaimer: Mutant author speaking here.
Under the assumption you are using rails with rspec you can test your models via the following commandline:
RAILS_ENV=test bundle exec mutant -r ./config/environment --use rspec YourModel
There is a README section explaining rails integration. In case you run into problems please visit to make sure you have the latest instructions.
Related
This is quite a 'newbie' question but I've been searching and can't seem to find anything to solve an error with using hyperclient in a rails app, in one of my Model's methods.
Whenever I run rails c I get the error
NoMethodError (undefined method `new' for Hyperclient:Module)
In my gemfile
gem "hyperclient"
-- ran bundle install
in model app/models/artwork.rb
class Artwork < ApplicationRecord
require "hyperclient"
def self.test_artsy
api = Hyperclient.new('https://api.artsy.net/api') do |api|
puts api
end
end
end
I've looked at the docs on hyperclient and have seen that they do have a method for .new (also on their examples) so I know it's something I've done incorrectly but I'm not sure what else to try?
The code did work when opening irb in the terminal.
You haven't specified any version in your Gemfile so it might happen that Bundler will not install the latest version and that's what I am guessing might happened here.
You can check which version is installed by doing:
cat Gemfile.lock | grep hyperclient
You have at least two options here:
1)
bundle update hyperclient - this should update your Gemfile.lock to the latest version
2)
bundle remove hyperclient
bundle add hyperclient --version "0.9" - this will update your Gemfile and then run bundle install that will regenerate your Gemfile.lock
The second option is recommended since it is a good practice to always specify version for the gems you are using.
The Problem:
I have a Rails application and I can successfully run the RSpec suite using rspec spec. I've also made a neat little gem that also has a pretty little copyright next to it. Its not open source. Its a gem that belongs to that Rails application and that Rails application only.
Now, this gem has some specs and it also pumps out a nice string of green. So, to test the whole application I might do:
$ rspec spec
$ cd custom_gem && rspec spec
That's nice, but what if I want to run the whole suit from one line? Well I could do:
$ rspec spec custom_gem/spec
But, this doesn't work in my case because the gem is also a Rails engine. Due to this, it has to connect to a dummy application within the gem.
Now that you know this, I can finally ask my key question:
How do you run a spec for a rails engine and the spec for your main application given that your rails engine should also have a dummy application to test upon?
If both of them are running correctly on their own, why not just make a bash alias?
alias test_all='cd /full/path/to/gem && rspec spec && cd /full/path/to/rails && rspec spec'
So the crux of the problem, is I get the following error when running
rake -T
WARNING: Global access to Rake DSL methods is deprecated. Please Include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method SeenicServer::Application#task called at /home/grantismo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'
rake aborted!
no such file to load -- parse_tree
So obviously I did, gem install ParseTree.
Running gem list -d ParseTree produces:
*** LOCAL GEMS ***
ParseTree (3.0.7)
Author: Ryan Davis
Rubyforge: http://rubyforge.org/projects/parsetree
Homepage: http://rubyforge.org/projects/parsetree/
Installed at: /home/grantismo/.rvm/gems/ruby-1.9.2-p180
ParseTree is a C extension (using RubyInline) that extracts the
parse tree for an entire class or a specific method and returns it
as a s-expression (aka sexp) using ruby's arrays, strings, symbols,
and integers
it looks like I'm using the correct rake
which rake
/home/grantismo/.rvm/gems/ruby-1.9.2-p180/bin/rake
Most of the explanations I've read say to run sudo gem install ParseTree, but I don't understand why I should be installing with sudo if I'm managing gems through rvm.
Any ideas? I'm a unix noob, so it might be something simple. Thanks for your time.
You need to make sure your Gemfile has a gem 'ParseTree' line in it, otherwise Rails won't load it (even if the system has it installed).
After adding the line, do a bundle install.
I am trying to build Noosfero (http://noosfero.org/), a project done in Ruby, but I am pretty new in Ruby and Linux (my current environment).
I am following the instructions in their tutorial (http://gitorious.org/noosfero/noosfero/blobs/master/INSTALL and http://gitorious.org/noosfero/noosfero/blobs/master/HACKING).
I was supposed to run an apt-get install with many packages, everything worked except for libgettext-ruby-data, to which I get a message that "E: Package libgettext-ruby-data has no installation candidate".
I then download the source and try to run "rake db:schema:load", which I get the following error:
"rake aborted!
uninitialized constant Dependencies
/home/user/noosfero/Rakefile:10"
My rake file is the following:
require(File.join(File.dirname(FILE), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails' #this is the line that the dependency can't be found
I searched around and found this question here: Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError) , but changing the config files didn't help and I could wasn't able to downgrade my RubyGems because I do not know how to do that (gem -update returns a message that I have to do that using apt-get, but I can't find out in which package the gem program is).
The first time I run Rake, I get a message saying:
"I: Installing Debian-installed Rails from /usr/share/rails into vendor/rails.
I: Please note that the recommended Rails version is 2.1.0, and that other versions might not work"
But I don't know how to downgrade my Rails version.
I've got many paths to follow, so I've got many questions, I hope you can help me:
1- Does anyone knows how to fix it directly?
2- How can I downgrade Gems?
3- How can I downgrade Rails?
4- Where can I download gems and how can I install it? (The documentation provides a link, but this link is VERY strange: http://www.yotabanana.com/hiki/ruby-gettext.html?ruby-gettext ).
Any help is very appreciated.
Thanks,
Oscar
Edit: can this error be a problem in the project I downloaded and not in my environment? After some research I am starting to think it is, can it be?
It would help if you share your rake version, by the way.
In the meantime, take a look at this:
https://github.com/jimweirich/rake/issues/33
(Only valid for rake 0.9.0, though).
This was a version conflict I had with the project I was trying to build, not it is solved :)
First of all, I'm a Noosfero developer and I need to admit that the process of preparing the environment to run Noosfero right now is pretty nasty (unless you only want to run it in the production mode since we've got a debian package). But this problem is close to an end since we're a building a vagrant box (for more info see http://vagrantup.com/) to noosfero. Things are going to be much better. But regardless all this nastiness and not having the box yet, Noosfero was supposed to run if you followed all the steps in the INSTALL instructions. Let me try to help you.
Are you using Rails 2.1.0? The best way to do so is to uninstall rails from your system (if you installed through apt-get) and install through rubygems:
gem install rails -v=2.1.0
To avoid problems ensure that there isn't any other version of rails installed through rubygems (gem list).
If you still having problems to run the schema load, run it with --trace and post it here.
If you have other problems you can try contacting us through noosfero-dev#listas.softwarelivre.org or the irc #noosfero at FreeNode.
I'm trying to get tags working in my rails application and want to use acts_as_taggable. Firstly I followed the instructions I found in Rails Recipies (a free sample bit online) that used the acts_as_taggable plugin. However, I then found this site which seems to have a gem for acts_as_taggable which is more advanced (has options for related tags etc).
I've tried to follow the instructions there to install it, but I keep getting errors.
Firstly I installed the gem as normal (gem install acts_as_taggable) and then I tried various ways to get rails to recognise and load the gem. The require_gem listed on the site didn't work (I assume that is an old command that has been removed) and neither did a straight require (although that has worked for my bluecloth gem).
I've then tried using config.gem 'acts_as_taggable' but that keeps telling me that I haven't got acts_as_taggable installed and asks me to run rake gems:install. No matter how many times I run that it still gives the error!
The result of the gem query -l -n acts_as_taggable lists acts_as_taggable as an installed local gem.
I've tried running gem check and that doesn't show any problems.
The response I get when I try to require it from the console is:
MissingSourceFile: no such file to load -- acts_as_taggable
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `ge
m_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `re
quire'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_suppo
rt/dependencies.rb:510:in `require'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_suppo
rt/dependencies.rb:355:in `new_constants_in'
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_suppo
rt/dependencies.rb:510:in `require'
from (irb):1
It looks like for some reason it can't find it. Any ideas why?
You could also try acts_as_taggable_on_steroids:
This plugin is based on acts_as_taggable by DHH but includes extras such as tests, smarter tag assignment, and tag cloud calculations.
I've used it recently. Aside from some performance issues, it works very well and, unlike taggable, is under active maintenance.
Have you tried running something like "gem query -l -n taggable" to check whether it has installed correctly into your local gem repository?
If it has you could use some of the built in checks against it - Gem is good for this - to make sure it installed as it is supposed to.
That would be my first avenue to explore.