I have a Rails 3.0.10 project using the minitest-rails gem (running in JRuby 1.6.5 == Ruby 1.9.2). I would like to use all of our existing Test::Unit test cases with minimal changes in order to start using Minitest. Right now I can run tests but many fail because fixtures are not being loaded. I have yet to figure out how to make that work. If I change ActionController::TestCase to MiniTest::Unit::TestCase then the fixtures function doesn't work. I've tried the links here and the links within that one without any success. So the question is how to continue using ActionController::TestCase with the MiniTest gem or how to switch to MiniTest::Unit::TestCase and have fixtures load.
Please try upgrading to version 0.1, which is dramatically improved across the board. Stuff like fixtures actually work now.
Related
I'm writing an application in Rails 5 and using Rspec for tests. I'm having a lot of trouble with require 'some_model' or require 'some_controller' in my spec files. Every time I run a spec, it acts lost and doesn't seem to understand that it's in a Rails app. The suggestions I've seen range from
config.autolad_paths += %W( #{config.root}/app )
to
$LOAD_PATH << '~/my_app/app/models' which sort of works, except that my tests throw an unitialized constant for ApplicationRecord
So for all the digging around I've done, I still haven't found a good way require my MVC files while keeping my specs and spec_helper clean. There doesn't seem to be any defacto way to do so, so how do you all suggest doing it?
can you not take on the entire stress of RSpec configuration. Use the rspec-rails gem and look through the documentation to use it within your app. I guess you can get a base config with rails generate rspec:install after including the gem in your project.
I notice after reading the rails guide docs
that minitest comes with the newer Ruby versions out of the box, so it's available right away, no need to install anything else. Rails 4 by default use that.
If fact i use the minitest-reporter gem and it work like charm.
The confusion comes when i see examples defining the :test group of the gemfile like this:
group :test do
gem 'minitest-rails'
gem 'minitest-rails-capybara'
gem 'minitest-colorize'
gem 'minitest-focus'
end
Why is the need of include a minitest-rails gem ?? To use some rails generation later or other kind of specs ??
I'm kinda confused here so any thought about Rails 4 Minitest integration will be appreciated.
According to the mini-test rails README, it makes it so Rails generators for tests will generate in minitest style. It also makes it so minitest style actually works in Rails ActiveSupport::TestCase test classes. (which is what Rails test cases do).
minitest comes with ruby, but the Rails' ActiveSupport::TestCase, which Rails test classes all are, doesn't normally use minitest. minitest-rails makes it so it does.
This project aims to enable Minitest within the Rails TestCase classes. Your test will continue to inherit from ActiveSupport::TestCase, which will now support the spec DSL. You can generate test files with the standard model, controller, resource, and other generators:
https://github.com/blowmage/minitest-rails
One thing that makes this more confusing, is that in newer versions of ruby [i accidentally said 'Rails' before, but it's newer versions of ruby that matter], it's true that Minitest is there and old Test::Unit is not. But Minitest has a sort of "pretend to be Test::Unit" mode -- that's what Rails ActiveSupport::TestCase ordinarily uses, the old Test::Unit style of testing -- even if it's actually the minitest library providing it. minitest-rails makes it support the newer Minitest::Spec::DSL style.
minitest-rails is already a dependency of minitest-rails-capybara which you are using and have added to the test group.
So regardless of whether you explicitly add minitest-rails to the Gemfile or not, it will be installed for your application. However, you might wish to explicitly specify a specific version of minitest-rails that you want to use, and in such case you should add the gem to your Gemfile with the wanted version (something you are not doing in your code).
If you have no interest in using Minitest's spec DSL then you don't need to include minitest-rails. If you have no interest in Capybara's spec DSL then you don't need to include minitest-rails-capybara, although if you want to use Capybara you will need some other mechanism to add it to your application. The minitest-capybara gem doesn't do any rails integration.
It is possible that these two libraries are added to add the Capybara support even though you use test style tests and not spec style tests. The minitest-rails-capybara gem adds generators for Capybara tests in both test style and spec style. Try git blame on your Gemfile to find the commit where those two lines were added, as the commit message might explain why they are in the application.
Can't configure Rubymine to work with minitest normally. All the time it throws me exceptions
Unable to attach test reporter to test framework or test framework quit unexpectedly
Also, I can't run test by one (only all test running working), because in that case context do not load and all my classes goes to be undetermined constants (NameError: uninitialized constant <MyVariableType>).
I'm currently working with RubyMine 5 via Windows 7. (Ruby 1.9.3).
If someone know how to configure it properly i'll be very appreciate for your help.
Ok, great! I finally solve all my problems and now my rubymine working with minitest.
The short instruction:
Read this manual and do all the stuff step by step very careful
If it helps then say 'Yohuu!!!' and dancing victorious jig, if it
still not working correctly goes to step 3
Add 'test-unit' gem to your gem file and update it with bundler.
When creating test do not forget to add require 'test_helper' add
the top of the file.
IMPORTANT: your test method names should start with 'test_' pattern, like test_my_supercool_method
UPD 1: If you use Ruby 2.0, you don't need to use win32Console gem on Windows platform, even if jetbrains doc say that you should.
If you are following this guide (https://www.jetbrains.com/help/ruby/2016.1/minitest.html?origin=old_help), you don't need to include minitest-reporters in your Gemfile or have this:
require 'minitest/reporters'
MiniTest::Reporters.use!
in your test_helper.rb file if you are using MiniTest 5 or newer. I was following a tutorial that was a little outdated and ran into this issue. Be sure to delete your .idea directory and restart RubyMine and you should be good to go!
I just went through this with the undefined method 'format_backtrace' error, and was getting green passing when the tests were failing and crashing.
Read the notes closely, if you are running minitest > 5.0, you don't need the minitest-reporters gem.
If you include it, perhaps like I did following the instructions, then you get the errors, and errors are not reported- (in my case, anyways). So back out and remove the require minitest/reporters from your tests, and the MiniTest::Reporters.use! line and things should be good to go.
I'm just converting an old gem to use the Rails 3.1 plugin template (rails new plugin ...) and after generating a basic 'dummy' app with a few models and controllers I get:
undefined method `images' for #<ImagesControllerTest:0x007fac92d1ea48>
After running the tests. This appears to be an issue with the fixtures methods not loading correctly. I followed the standard practice for getting this setup; do I need do anything else to get the dummy application to include fixtures?
Found a solution. It appears that using rails plugin new does not include in test_helper.rb:
class ActiveSupport::TestCase
fixtures :all
end
Adding fixes.
We are writing a Rails application that is using CouchDB as its data store. We're BDD/TDD'ing with RSpec and Cucumber, which is using WebRat for webpage testing
I'm trying to remove ActiveRecord as one of the resources that is being loaded by rails but its causing the cucumber tests to fail. I've removed all references that I can find (fixtures, environment files, etc...) but it still fails without it.
Has anyone seen this? The application runs fine without, but the test don't.
edit
I did remove the framework in env file, I also removed all the transactional fixture code. We're using the latest version of rspec and rspec-rails.
First stab at the problem.
Really I need a little more information, but...
Assuming you have done this in config/environment.rb:
# Skip frameworks you're not going to use. To use Rails without a database
# you must remove the Active Record framework.
config.frameworks -= [ :active_record ]
and are using rspec-rails 1.2.6, you would be getting an error like uninitialized constant Spec::Matchers::Change::ActiveRecord
which was brought up in ticket #810. It was fixed for 1.2.7, which was released only two weeks ago.
If that turns out not to be your problem, could you post the errors you've been getting and maybe some more information about your test environment?