this is my first time using RubyMine and I can't make the Test Framework recognize the tests.
If I run the greed.rb file it shows the result of the tests:
But if I run the tests it shows this:
I have read the question about minitest and tried to apply it to test-unit but it did not worked.
This is the content of my Gemfile:
gem 'test-unit', '~> 3.0.8'
And this is part of the ruby class that contains the tests:
require 'test/unit'
def score(dice)
# code of the function
end
class Greed < Test::Unit::TestCase
def test_score_of_an_empty_list_is_zero
assert_equal 0, score([])
end
end
I'm probably missing something but I haven't been able to find a solution.
To solve it I firstly restructured my project in the following way
/lib
greed.rb
/tests
test_greed.rb
Gemfile
Then I moved all of my tests to the new file
require './lib/greed.rb'
require 'test/unit'
class Test_Greed < Test::Unit::TestCase
# code for the tests
end
Finally I went to File/Setting/Project/Project Structure and marked the tests folder as Test (this should change the color of the folder icon).
Now I can run the tests using the testing framework
Related
I'm creating a gem called brval, and my folder structure is:
lib/
brval/ ... brval files
cep/ ...cep files
brval.rb
I can require and use all modules and classes inside brval/ folder, I just need to add
require 'brval/file.rb' inside brval.rb and then use extend or include to add the modules to brval main module.
But for files inside cep/ folder I can't do that, doesn't work.
I tried to require 'cep/cep_file' (is a class) inside brval.rb module
But when I build my gem to test it I always got the same error:
lib/cep/cep_file.rb:1:in '<top (required)>': uninitialized constant Cep(NameError)
My cep_file module and class structure is:
module Cep
class CepFile
methods...
In my gemspec file I also have:
spec.files = Dir['lib/**/*', 'README.md']
spec.require_paths = ['lib']
I have a requirement,
Simplecov should print this line
Coverage report generated ...
only if the test suite is green.
Is this possible?
Here's my initializer
SimpleCov.start do
add_filter "/test/"
coverage_dir "/tmp/coverage/"
end
There is a at_exit hook in SimpleCov where you can skip the message
SimpleCov.at_exit do
SimpleCov.result.format! if all_test_passed
end
but could not find a workaround for 'all_test_passed'. Did not find a way to get summary so that i can check if all tests passed.
I'm getting the following error when I try to run my cucumber tests in my (local) Jenkins:
/Users/kris/.rvm/rubies/ruby-1.9.3-p545/bin/rake --rakefile android/rakefile
(in /)
rake aborted!
cannot load such file -- cucumber
My rakefile looks like the following:
require 'cucumber'
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features) do |t|
t.profile = 'ci'
end
task :default => :features
I'm just trying to set up a really basic run, it looks like I need to either set up a plugin for cucumber (which I thought I had done) - or set some variable to make cucumber available to Jenkins.
Thanks for any help/suggestions!
I'm trying to implement shoulda for test automation. I tried this code:
require 'test/unit'
require 'shoulda'
require 'shoulda-context'
class TestClass < Test::Unit::TestCase
context 'Languages' do
should 'Ruby' do
puts 'Ruby'
end
should 'Java' do
puts 'Java'
end
should 'Python' do
puts 'Python'
end
end
end
When I execute that code, it outputs according to alphabetical order of shoulda test methods:
Java
Python
Ruby
Actually, I want the output in the order I wrote the methods:
Ruby
Java
Python
To do that, what will I have to use in my code?
Actually it is preferred not to run test in a specific order. It is better to run them in a random order, because that allows you to recognize if there are tests that depend on other tests. If tests only pass in a specific order, it is a indicator that you are doing something wrong.
If you want to do that nevertheless:
class TestClass < Test::Unit::TestCase
context 'Languages' do
self.test_order = :defined
...
See: http://test-unit.rubyforge.org/test-unit/en/Test/Unit/TestCase.html#test_order=-class_method
I work with Middleman to develop, test and build my HAML & SASS Projects.
Now I also like to work with require.js. Is there any way i could integrate the R.js build into the Middleman build?
Did you make any experience with it? How do you handle require.js in middleman?
As far as just "running r.js" is concerned, it's pretty straightforward:
Save r.js into the project's root.
Define a custom extension (config.rb) which executes r.js after the build:
module RequireJS
class << self
def registered(app)
app.after_build do |builder|
exec('node r.js -o build/javascripts/app.build.js');
end
end
alias :included :registered
end
end
::Middleman::Extensions.register(:requirejs, RequireJS)
Activate custom extension (config.rb):
configure :build do
…
activate :requirejs
end
r.js can be used with node via the command line, just like middleman. I don't know how exactly you use middleman, but incorporating another command in your workflow shouldn't be a problem. You can find instructions on how to use r.js from the command line here.