Disabling the running-twice with Zeus in Rails 4 minitest? - ruby-on-rails-4

Zeus has a known issue where it runs specs double if you include the default "autorunner" for a testing suite.
It is common to see tests running twice when starting out with Zeus.
If you see your tests/specs running twice, you should try disabling
require 'rspec/autotest' and require 'rspec/autorun' (for RSpec), or
require 'minitest/autorun' (for Minitest). (see #134 for more
information).
https://github.com/burke/zeus#important
However, Rails4 minitest includes "rails/test_help" which is a file in Railties 4.0.0; which includes yet another custom runner. And does other generic of setup and configuration.
For Rails4 with default minitest, there is no simple include to leave out, it seems.
Is there a solution for this?

i was just facing this same problem with Rails4+minitest+zeus.
After i include gem "minitest-rails-shoulda" in my Gemfile, zeus starts to run tests twice.
I just changed the gem orders at Gemfile and it solves!
Gemfile with Zeus running twice:
group :test do
gem "minitest-rails-shoulda"
gem 'minitest'
#...
end
Gemfile CORRECT:
group :test do
gem 'minitest'
gem "minitest-rails-shoulda"
#....
end

Related

"wkhtmltopdf" and "pdfkit" gems -- error "ContentNotFoundError". How to fix it?

I have a Rails app at heroku. I'm using these 2 gems for generating pdf files:
gem "wkhtmltopdf-heroku", "~> 2.12", ">= 2.12.3.0"
gem "pdfkit", "~> 0.8.2"
I sometimes, but not always, I have an error:
ContentNotFoundError
It's probably due to a bug in the C++ library on top on which the gem is built - https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2051
There's even a workaround as they say.
My question -- if that workaround really works, how can it be applied to the gem? How to get rid of the exception in the gem?

Why does SimpleCov trigger when rake db:schema:load is executed?

If I have a .simplecov file, then when I run RAILS_ENV=test rake db:schema:load, I get a coverage report.
If I move the code from .simplecov to my test_helper.rb file (I use MiniTest), this does not happen.
I expect that this should never happen - loading the schema in the test environment is not a coverage test.
The reason this is annoying is that it causes my schema to load on CircleCI, generates a coverage below my threshold, and then fails the build.
I probably posted this question before a recent change to the simplecov readme... the change I needed to avoid this problem was to update my Gemfile to turn off auto-requiring of the simplecov gem:
gem 'simplecov', require: false
I then explicitly added Simplecov to my test/test_helper.rb as recommended in the README and that fixed this problem.

Converting Rails 2.3 to Rails 4.0 environment.rb

I have an application that runs fine under Rails 2.3.2.
I'm trying to upgrade it to Rails 4.0, using nginx and unicorn.
My config/environment.rb has these lines that don't work:
Rails::Initializer.run do |config|
config.load_paths += %W( #{RAILS_ROOT}/vendor/gems/ #{RAILS_ROOT}/app/exceptions/ )
config.action_controller.session = { :session_key => "my_app", :secret => "c4c6eee57d9af4f2e1a9c56a49d974b7" }
config.gem "mocha", :version => '>=0.9.4'
The error message I get in unicorn.log is
ERROR -- : uninitialized constant Rails (NameError)
/home/art/config/environment.rb:70:in `<top (required)>'
and line 70 is the " Rails::Initializer.run do |config|" line above.
I guess these things have been moved out into some initializer file somewhere?
I guess bundler now handle gem versions, so I should just move the "config.gem... :version ..." lines into my Gemfile?
And where should I set session_key?
Thanks for any advice.
in the new Rails require the application.rb file:
# Load the Rails application.
require File.expand_path('../application', __FILE__)
In the application.rb require rails:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
usually the session_key is in a new initializer (under initializers folder - look here)
anyway try to run rake rails:update it might help you change some stuff,
or create new rails project and start to copy things from there.

Rails + Prawn: undefined method `table' for #<Prawn::Document:0x007fda2d594a98>:

I'm using Rails 4 + prawn_rails + the latest version of prawn (v 1.1.0) and I noticed in the changelog here: https://github.com/prawnpdf/prawn/wiki/CHANGELOG that tables are now separated.
I followed the instructions to require "prawn/tables". I did this by adding a file in my lib directory:
lib/prawn.rb
require "prawn/tables"
I restarted my rails server and I still get the error:
NoMethodError - undefined method `table' for #<Prawn::Document:0x007fda2d594a98>:
How do I fix this?
You should add these lines into your Gemfile.
gem 'prawn', '~> 1.2.1'
gem 'prawn-table', '~> 0.1.0'
The line in the documentation is WRONG. add require 'prawn/table'
to your .pdf.prawn file on the top and it will work.

Given a typical Rails 3 environment, why am I unable to execute any tests?

I'm working on writing simple unit tests for a Rails 3 project, but I'm unable to actually execute any tests.
Case in point, attempting to run the test auto-generated by Rails fails:
require 'test_helper'
class UserTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
Results in the following error:
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
test_helper (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from user_test.rb:1:in `<main>'
Commenting out the require 'test_helper' line and attempting to run the test results in this error:
user_test.rb:3:in `<main>': uninitialized constant Object::ActiveSupport (NameError)
The action pack gems appear to be properly installed and up to date:
actionmailer (3.0.3, 2.3.5)
actionpack (3.0.3, 2.3.5)
activemodel (3.0.3)
activerecord (3.0.3, 2.3.5)
activeresource (3.0.3, 2.3.5)
activesupport (3.0.3, 2.3.5)
Ruby is at 1.9.2p0 and Rails is at 3.0.3.
The sample dump of my test directory is as follows:
/fixtures
/functional
/integration
/performance
/unit
-- /helpers
-- user_helper_test.rb
-- user_test.rb
test_helper.rb
I've never seen this problem before - I've run the typical rake tasks for preparing the test environment. I have nothing out of the ordinary in my application or environment configuration files, nor have I installed any unusual gems that would interfere with the test environment.
Edit March 9th
Xavier Holt's suggestion, explicitly specifying the path to the test_helper worked; however, this revealed an issue with ActiveSupport.
Now when I attempt to run the test, I receive the following error message (as also listed above):
user_test.rb:3:in `<main>': uninitialized constant Object::ActiveSupport (NameError)
But as you can see above, Action Pack is all installed and update to date.
Edit March 13th
When attempting to run tests using rake test:units the following stack trace is dumped to the console:
test/unit/bookmark_test.rb:3:in `<top (required)>': uninitialized constant Objec
t::ActiveSupport (NameError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `block in <main>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `<main>'
rake aborted!
So looking into the file listed above, I see the following:
#!/usr/bin/env ruby
# Load the test files from the command line.
ARGV.each { |f| load f unless f =~ /^-/ }
To my knowledge, everything looks as expected.
Your test/test_helper file should have been created when you generated the application. It contains this valuable content:
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
end
The second line here is the most important: it requires the config/environment.rb file at the root of your application, which in turn requires a lot of other things, including the valuable (I like that word today, ok?) ActiveSupport constant.
When you generate a controller, model or scaffold it'll also generate tests for those. I just ran rails g scaffold ticket in my app and it generated test/unit/ticket_test.rb which contains this:
require 'test_helper'
class TicketTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
The first line of this file will require the test/test_helper.rb file that we jut saw. This will load ActiveSupport and the TestCase class within it, thereby making this test feasible. Everything else just flows on from there.
With all that explanation out of the way (even though it's something that you already know), I'm placing a large wager on it's something that's masscaring your LOAD_PATH, causing the test directory to be removed from it.
What's really unusual is that when you do specify the full path to the test/test_helper.rb you're saying it loads it, but ActiveSupport is still undefined. Well, that should be loaded as-per the description above. Is it actually loading config/environment.rb? Can you put something such as:
puts "LOADING CONFIG/ENVIRONMENT.RB"
At the top of your config/environment.rb file and then run the tests again? It should be output. Very unusual.
Continuing on the thread about LOAD_PATH... Got a dirty little secret you're not telling us about?
Actually, Dan Cheail makes a good point. You could be running the tests using ruby test/unit/ticket_test.rb in which case test_helper wouldn't be available, but still that still doesn't explain why when you specify the full path you're still getting an undefined constant ActiveSupport.
If you want to run a single test you should be doing this:
ruby -Itest test/unit/ticket_test.rb
That -I option there adds the test directory to the load path, meaning the test_helper file will be available through a straight require 'test_helper'. If it still errors after this, I reckon your test/test_helper.rb is either empty or broken.
The problem you're having is the way you're executing tests. Simply calling ruby test/unit/user_test.rb doesn't set up the load path, which explains the problems you've been having.
rake test:units is what you want and should work straight away.
Sorry about the post here, but I am unable to comment on questions yet.
what environment are you running, Win (has an issue with a .gemspec file) Linux, Mac?
Are you using RVM?
Test-Unit is installed by default with Rails, if you installed the gem Test-Unit you will get a conflict between the 2. try uninstalling the gem and your tests should start working.
If running on windows I would gem uninstall "autotest", then navigate to the following dir
drive:\Ruby192\lib\ruby\gems\1.9.1\specifications
In here you will find .gemspec files. Ensure that you dont have 2 autotest.gemspec files or any, for that matter. if so remove(delete) them, then download and gem install the autotest gem again. Grab the latest by using version switch.
You should be able to run your autotests. I did come across this once before, so to fix I simply removed the view and helper test files and wrote everything in the standard test file. Other than that I know running on windows autotest had issues, because of the ruby installer and bundler not clearing out things correctly and forgetting files.
I will find the link for you, to better explain.