outputting html reports using .rspec file - ruby

I am new to rspec testing.
I have a folder which contains _spec.rb files. When I run the specs using:
rspec --format html --out rspec_results.html "/Users/phukb/prpc-platform/prpc-platform/test/giza/coreui/ClientPerformance/RDL/spec/"
I see that the tests are run successfully and the results are posted in rspec_results.html.
However, when I create a .rspec file in my project with:
--format html --out rspec_results.html
and run the specs using
rspec "/Users/phukb/Desktop/prpc-platform/prpc-platform/test/giza/coreui/runtime_regression/featuresets/DynamicLayout/Repeating/MicroDC/Pagination/spec"
I see that the results_rspec.html is not getting created. Am I missing something here?
here is my folder structure

If you are running the rspec command from ../RDL folder,then the .rspec file should also be there.
That is, the path of the file should be ../RDL/.rspec, not ../RDL/spec/.rspec.

Related

RubyMine IDE Cannot Find Spec Files in Spec directory

I have loaded a Ruby project into RubyMine, that has it's spec files located in a spec directory, as usual. Right-clicking and selecting 'run' on any single spec file correctly runs it. Right-clicking and selecting 'run all' on the specs directory causes every test to fail with the following message:
Fail to load: /Users/nathaniel/repos/close-web/spec/compositions/analysis/analysis_data_spec.rb:1
Exception message: cannot load such file -- spec_helper
Inside the launch configuration, the 'Tests folder' seems to be set correctly:
/Users/nathaniel/repos/close-web/spec
And the working directory as well:
/Users/nathaniel/repos/close-web
The Ruby arguments are set like this:
-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -Itest
(There is some indication on the RubyMine website that -Itest is required.) Under the Bundler tab 'Run the script in the context of the bundle' is checked as well. I'm unclear what else RubyMine might need to be able to recursively find and execute the tests. Running them from the command line works fine:
~repos/closeweb $ bundle exec rspec spec
... (all the tests running)
Finished in 6 minutes 27 seconds (files took 13.39 seconds to load)
1054 examples, 0 failures, 108 pending
What configuration is wrong here that all the tests won't run?
Given that your folder is called spec, not test, you need to -Ispec, not -Itest.
In other words, your RubyMine arguments should be:
-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -Ispec
From the ruby man page:
-I directory Used to tell Ruby where to load the library scripts.
Directory path will be added to the load-path variable ($:)

Cucumber html report causes test failure

I'm running tests in parallel on Cucumber using parallel_cucumber.
I'm finding that when I choose to have the reports in junit, everything runs smoothly. If I change the format of the test to html, some tests keep failing. Yet running them in isolation, no parallel_cucumber and it works fine. I switch it back to junit and the tests all pass again.
The errors I'm getting are unable to find fields on screen. Could the html be messing with the step definitions? I've searched and searched and can't figure out why it's failing.
Has anyone experienced a similar issue?
My cucumber.yml file contains:
html: --format pretty --format html --out Reports/report<%= ENV['TEST_ENV_NUMBER']%>.html --format ParallelTests::Cucumber::FailuresLogger --out Reports/cucumber_failures.log
my junit profile is:
junit: --format pretty --format junit --out Reports/ --format ParallelTests::Cucumber::FailuresLogger --out Reports/cucumber_failures.log
On trial and error, I found that it was the background steps causing the failure. I moved these to the scenarios and lo and behold, the tests stopped failing

ruby rake rspec ci_reporter_rspec prevents multiple output formats from being generated

I am trying to integrate this gem https://github.com/ci-reporter/ci_reporter_rspec in to my rake task below to output the following formats:
progress: on screen during run
documentation/html: separate files. "test/reports/spec.txt" & "test/reports/spec.html" respectively
xunit: generates files from ci_reporter_rspec
The progress format displays on screen, the xunit files are generated but documentation and html files are not generated. I can confirm when ci_reporter_rspec is not included then it works as design minus xunit files. I need all formats generated, can anyone see what I'm missing?
require 'rspec/core/rake_task'
require 'ci/reporter/rake/rspec'
RSpec::Core:RakeTask.new(:spec => ['ci:setup:rspec']) do |t|
t.rspec_opts = '--format progress --format documentation -o "test/reports/spec.txt" --format html -o "test/reports/spec.html"'
end
I think this is a bug in ci-reporter since the same problem happens for me. But, when I remove CI reporter this works just fine. I have opened an issue here.

Stop Loading spec_helper from spec directory when running another set of tests

I have two spec folders. The first one is /spec and it what you typically would see. I have another called /live_integration_tests. When I run rspec -I live_integration_tests ./live_integration_tests I'm actually pulling in the spec/spec_helper.rb file as well. Is there a way to get rspec to ignore the spec_helper file in the spec_helper folder.
I've also tried rspec -O live_integration_tests/spec_helper.rb ./live_integration_tests
but that didn't do it either. Everything else in the help didn't look very promising.
I found a fix for this.
rspec --default-path ./live_integration_tests runs only the rspec spec_helper in the ./live_integration_test folder and not the default one in ./spec.

How do I require a ruby file from child directory

I have the following structure
tests
specific tests
first_test.rb
more tests
second_test.rb
test_helper.rb
Now I am trying to require test_helper in both first_test and second_test. The following works
require '../test_helper.rb'
and from command line I should be under specific tests and execute
ruby first_test.rb
How can I get more flexibility ie. I want to be in any directory and execute these tests. Currently I am getting 'no such file'. This is not a rails app but in rails I could simply do require 'test_helper.rb'
Bonus points for making this work with rake.
Put your test_helper and other helpers in a separate directory like
/home/XXX/projects/test_project/lib/
or wherever you like and use base directory like
Dir["base/path/to/your/helper/*.rb"].each {|file| require file }
or from my above example
Dir["/home/XXX/projects/test_project/lib/*.rb"].each {|file| require file }
Thats it.
Now add this line to the beginning of every test you want to run separately from any directory.And forget about the directory issue.

Resources