Run Ruby Unit Tests(Test::Unit) inside the Code - ruby

Does anybody know how I do run a unit test(Test::Unit) within Ruby code itself? I couldn't find anything online to help me out. As we all know, you run unit tests from the command line by executing "ruby your_test_name.rb' I basically don't want to run from the command line but I want to run within the ruby code itself. Does anybody have any ideas? Thanks in advance for all your help.

How can u imagine it?
If you wanna start your code (tests) automatically after changes check out gem guard.
1) Setup guard
Add to your Gemfile
gem 'guard-test'
than run
bundle install
or if you don't use bundle
gem install guard-test
2) Generate guardfile
guard init test
3) Run it
guard
more about guard

Related

zsh: command not found: hiptest-publisher

I'm using hiptest-publisher in order to push test results on the cucumber studio platform. The tests run and pass.
I installed Ruby and then ran gem install hiptest-publisher.
When I try to run this command to push the test execution result back to Cucumber Studio:
hiptest-publisher --config-file=<path> --push="target/cucumber.json" --push-format=cucumber-json --test-run-id=123
I receive this error:
Any advice to solve this problem is welcome.
Thanks a lot!
Problem solved!
How did I solve it?
Step 1
$ gem environment
Will tell you the EXECUTABLE DIRECTORY.
Step 2
Put whatever that value is in your PATH in your .bashrc or other shell config file.
export PATH="$PATH:/path/to/bin"
Thank you!

How do you get LiveReload to work with Octopress using Guard

I am using this guide to add liveReload to Octopress.
http://www.erikzaadi.com/2012/09/16/using-live-reload-with-octopress/
Once I get to 'rake generate && rake watch',
The command line spits out I am missing a specific gem; i.e.'rake-0.9.6', which is strange because I thought by installing the bundle took care of that.
I suspect that bundle is being saved elsewhere; but shouldn't that bundle be saved in the directory of my choosing (i.e. Sites/myproject?)
Add these two entries to your Gemfile, in the :development group:
gem 'guard'
gem 'guard-livereload'
Create a file called Guardfile containing something like:
guard 'livereload' do
watch(%r{public/generated})
watch(%r{public/.+\.(css|js|html)})
end
Start 2 shell tabs running these commands: rake generate && rake watch and guard
`
rake generate && rake watch
`
start guard LiveReload
`
guard
`
It’s neat to get LiveReload working with Octopress. However, the generation can finish after your page does a reload, so you won’t see your latest changes. I’ll update this blog post when I figure out a solution to that one. Until then, you may find it more convenient to manually refresh the blog page yourself.
It’s worth noting that if you’re running any other instance of guard- LiveReload, then one of these two copies will win and one won’t work. If you run a rails server this way, then this can bite you. It took me a bit of time to figure out why guard wasn’t working.
source
http://www.railsonmaui.com/blog/2013/04/27/octopress-setup-with-github-and-org-mode/#sec-4

How to develop a Ruby GEM without having to install it first?

I'm developing a GEM that I've forked and I'm trying to modify it slightly for my app.
I'm finding it difficult and time consuming because for every change I make I have to
uninstall
build
re-install
run the app
Is there an easier way of which doesn't require repeating all steps above?
To use it in some app using bundler
If what you mean is for using it in a app to test it / use it, you can just specify a path for your gem or even point to a git repo in the Gemfile http://gembundler.com/gemfile.html
Like
gem "mygem", :path => "~/code/gems/mygem"
To use it as a standalone gem. i.e: like rspec or rake that can run outside of an app.
Just specify the path to your gem binary when running the gem command, like:
$ ~/path_to_my_gem/bin/mygem some args
If you can execute inside your gem directory (i.e: the command does not create files in the current directory, or needs any specific files from the current directory), just do this:
$ ./bin/mygem some args
Note that this last one is just for future reference, I think it's not applicable in the OP context.
use require_relative to include your files:
require_relative 'yourgem/yourclass'
This is the documentation for the function.

Guard running outside of Bundler warning

When I run the guard command it gives the following warning:
Guard here! It looks like your project has a Gemfile, yet you are
running guard outside of Bundler. If this is your intent, feel free
to ignore this message. Otherwise, consider using bundle exec guard
to ensure your dependencies are loaded correctly.
Is this hinting to me that Rails is not configured to work with Bundler correctly, or is it normal? It's not the expected behavior in the tutorial I'm following.
You should run bundle exec guard instead. Or, alternatively, run bundle install --binstubs, then you may run guard with bin/guard (it creates a script at this location). This is the recommended way of running all commands coming from gems installed with bundle install.
(If I understand it correctly) It ensures that you run the specific version of the gem specified in the bundle as well as that this gem will not be able to run gems which are installed on you computer but not included in the Gemfile (which could fool you into believing that you project is fine until you try to run it on a different computer, or a production server, where the other gem would be missing). It also does a lot of of stuff which, frankly, I have no idea about.
More info in the docs.

cucumber debugger not stopping

I'm trying to debug a simple BDD test using cucumber. In order to do that, I inserted a debugger statement where I would like to break the control flow. But it seems that cucumber ignores this statement.
I'm running the tests executing:
rake cucumber:wip
It's rather simple, so I think the code isn' t worth pasting here. Thanks in advance
You don't have the rails-debug gem installed and/or included.
Make sure rails-debug listed in your Gemfile
If it's still not being included, make sure you run cucumber like:
bundle exec cucumber ...

Resources