How to make Rubymine working with minitest framework - ruby-on-rails

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.

Related

After installing paper_trail, get "irb: warn: can't alias context from irb_context." from rails console

I've tested this by running rails c both before and after git stash. On Rails 4.1 in Mavericks, after following the instructions to add the versions table and adding has_paper_trail to three models, whenever I run rails c I get
irb: warn: can't alias context from irb_context.
I've spent some time Googling without much luck, there's old threads talking about rspec, but I don't see how that's relevant since I'm not using it. Any ideas why this is happening?
RSpec used to polute provide Object top-level methods, e.g. describe, context, etc. Fortunately they've got rid of all the monkey patching in version 3, and now all these methods are namespaced under RSpec.
One can change this behaviour through the expose_dsl_globally config flag. For backwards compatibility, it defaults to true.
The warning shows up when you open the console because paper_trail automatically loads its rspec helpers when rspec is found. And it calls RSpec.configure before you have the chance to tweak your own configuration.
One possible solution would be paper_trail to disable the automatically loading and let users to load it themselves when they see fit. However, I am not aware of the internals of the library, so I can't guarantee this wouldn't break other things.
Best!
This is now fixed in papertrail 4.0.0, here's the commit.

how to set up nulldb in rails with rspec?

I'm almost new to rails development. I'm currently reading Avdi Grimm's Objects on Rails for having a #SOLID design in my rails apps instead of being forced to some conventions which will create mess and unreadable code and design.
I wanna setup nulldb and use it in my fast specs which are testing the business logic of the application but I can't get it to work. I read the installation guide at nulldb GitHub page here -> https://github.com/nulldb/nulldb. I installed the activerecord-nulldb-adapter gem and put it also in my Gemfile and ran the bundle install command so it's completely installed now. I have a spec_helper_lite.rb file which I use in my fast specs so I though it's a good idea to setup nulldb in it. Here's the code for nulldb part in my spec_helper_lite.rb file:
require 'nulldb_rspec'
def setup_nulldb
schema_path = File.expand_path("../db/schema.rb", File.dirname(__FILE__))
ActiveRecord::Base.establish_connection(:adapter => :nulldb,
:schema => schema_path)
NullDB.nullify(:schema => schema_path)
end
def teardown_nulldb
NullDB.restore
end
then I require this spec_helper_lite.rb in my fast specs and I call the setup and teardown nulldb method in before and after methods of my spec. when I run the specs I'll get the error Uninitialized Constant ActiveRecord::ConnectionNotEstablished (NameError). I tried different things like removing that establish_connection line in the setup_nulldb and I'll get the same error. I even required 'active_record' in my spec_helper_lite just to see what will happen and then I'll get the error "undefined method nullify" for NullDB module and obviously the spec became completely slow cause of requiring active_record. I searched a lot about how to setup nulldb and everything I saw explained about setting it up this way but it doesn't work for me. I use nulldb version 0.2.1, rails 3.0.0 and rspec 2.0.1
I appreciate your help about how to set this up correctly. Thanks in advance.
Sam
I was having similar issues (but using minitest, and activerecord independent of rails). I tried all the same stuff you mentioned. Turns out I was just using whatever was in rubygems. It looks like updating my Gemfile to pull directly from github resolved the issue:
group :development, :test do
gem 'activerecord-nulldb-adapter', :git => 'git://github.com/nulldb/nulldb.git'
end
You'll want to bundle install again after updating.

Test Unit fails to load xsd file

I have a ruby file that requires a file which has require 'xsd/qname'
and all my files work fine, but when I go to test them with test unit I keep getting these errors
LoadError: no such file to load -- xsd/qname
I've been scouring google for a while and fail to see a solution. (I'm new to test unit so it might be incredibly simple).
EDIT
I believe my problem is related to the fact that the code is in a gem and not the rails environment, therefore the code using it loads rails while these tests do not.
The odd part is if I go in the gem with irb, I can require 'xsd/qname', but I can't require 'soap/rpc/driver' which is another error I was getting
It's probably path related. It's difficult to advise a best solution without seeing how your project is laid out, but try replacing the require statement with:
require File.dirname(Rails.root + '/xsd/qname')
You may need to adjust that depending on where that file exists within your project.
I think the problem was using files built in ruby 1.8 with 1.9. Using soap4r solved my problem.
https://github.com/spox/soap4r-spox
Fyi if you just want to just rescue the error do this:
begin
require 'xsd/qname'
rescue LoadError
puts "xsd/qname not found...."
exit
end

rubymine only able to run model tests one by one

I am able to right-click on any of my 3 spec/models but when I right click the spec/models folder and select 'run all tests in models' I get 'Unable to attach test reporter to test framework'.
The first line of my model tests is: require 'spec_helper.rb'
I posted this answer for another question. It may help with this one as well:
On my system, the problem was the "redgreen" gem. It automatically colors the progress marks (dots) and the Test::Unit summary messages based on success or failure. There must be something in RubyMine that's trying to parse the Test::Unit results (the output of "rake test", I imagine), and it's choking on the ANSI sequences.
I commented out "require 'redgreen'" in my test/test_helper.rb, and the problem went away. I really like redgreen for executing "rake test" from the shell, though, so I put this in test_helper to make it work for both "rake test" and within RubyMine:
require 'redgreen' if $stdin.tty?
It may not be redgreen that's causing your problem, but be suspicious of anything which might create unconventional Test::Unit output.
Good luck!
I had the same issue and had to add the following to /etc/launcd.conf (I had to create this file as well):
setenv DYLD_LIBRARY_PATH /usr/local/mysql/lib/
and reboot. There are other ways to do it as well (a plist file, adding this environmental variable to RubyMine, etc… but this was most reliable. Of course, this assumes that you use MySQL.
The answer in the end for my setup was to fiddle around with the IDE settings including the ruby version, making sure it was 1.9.2 and the directories referenced in the config. screens were correct. This plus some restarts resolved the issue.

ActiveRecord dependency with Ruby, Rails, Cucumber, & RSpec

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?

Resources