If I have some test, e.g.
require_relative "Line"
require_relative "LineParser"
describe Line do
it "Can be created" do
load "spec_helper.rb"
@line.class.should == Line
end
it "Can be parsed" do
...
How can I print out the test group name - "Line" in this case.
I tried adding:
before :all do
puts "In #{self.class}"
end
but that gives: In RSpec::Core::ExampleGroup::Nested_3
, not Line
You may have specific reasons for wanting access to the test name while you're in the test...however, just in case it fits your needs to just have the line output in the test report, I like this configuration:
RSpec.configure do |config|
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :documentation
end
This gives me output like:
MyClassName
The initialization process
should accept two optional arguments
RSpec will read command line arguments from a file, so you could add the following to a .rspec
file in the root of your project:
--format documentation
--color
(This file may already exist depending on the gem you're using for RSpec and how you've installed it.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With