Cucumber Custom Logging


#1

Where and how do you put custom logger statements in cucumber? I
understood (more or less) how to do this in rspec in the spec_helper
file but I do not know where to start with cucumber.

I want to add a simple identifying text line in the log file to assist
in picking through the output. Something akin to:

Running Scenario: X

Feature I should have this logged

Feature This should get logged too

Running Scenario: Y

Feature This is somewhat different


#2

On Mon, Nov 24, 2008 at 8:40 PM, James B. removed_email_address@domain.invalid
wrote:

Where and how do you put custom logger statements in cucumber? I
understood (more or less) how to do this in rspec in the spec_helper
file but I do not know where to start with cucumber.

Are you using any particular framework along with Cucumber? -Like Merb
or
other?


#3

aslak hellesoy wrote:

On Mon, Nov 24, 2008 at 8:40 PM, James B. removed_email_address@domain.invalid
wrote:

Where and how do you put custom logger statements in cucumber? I
understood (more or less) how to do this in rspec in the spec_helper
file but I do not know where to start with cucumber.

Are you using any particular framework along with Cucumber? -Like Merb
or other?

Rails 2.2.2


#4

On Mon, Nov 24, 2008 at 9:00 PM, James B. removed_email_address@domain.invalid
wrote:

or other?

Rails 2.2.2

It depends what you want to log and when. Have you tried to put it in a
Before or After block?

I’m not sure exactly what you’re trying to achieve.

Aslak


#5

aslak hellesoy wrote:

On Mon, Nov 24, 2008 at 9:00 PM, James B. removed_email_address@domain.invalid
wrote:

or other?

Rails 2.2.2

It depends what you want to log and when. Have you tried to put it in a
Before or After block?

I’m not sure exactly what you’re trying to achieve.

Aslak

I am looking for where in hierarchy to put a global logger command that
will apply to each scenario and/or step, and probably what form the
command should take. I want to provide a text delimiter within
log/test.log to identify what activity takes place behind the curtains
when each scenario and step is run. Something like.

logger.info(“Running Scenario: #{scenario}”

logger.info(" Running Step: #{step}"

I tried to make sense out of the discussion surrounding ticket:

http://rspec.lighthouseapp.com/projects/16211/tickets/44-ability-to-teardown-failing-or-pending-scenarios-in-different-ways

Truth be told, I can only dimly grasp at what is going on. It seems
that the place to put something like I seek would be in features/support
or features itself. I gather that before / after block only work within
step files? If so then that requires each step file be modified to turn
custom logging on or off, which is something I would much rather avoid.


#6

I gather that before / after block only work within
step files? If so then that requires each step file be modified to turn
custom logging on or off, which is something I would much rather avoid.

I don’t think this is the case. Every Before/After that is in a required
file is run before a scenario. So in theory you could create one Before
(in for example env.rb) which would get called for all scenarios.

As for steps well, that sounds a lot trickier. I cannot think of a clean
way to get at that.

If you want steps now in a clean way I would suggest looking at making a
custom formatter. Cucumber supports multiple formatters so you could run
your rails logging formatter with other formatters. Bundle this up in a
–profile to save typing long command line args. The formatter knows
when every scenario is executed and when every step passes/fails/skips
etc.

If you look at the progress formatter in cucumber it should be a good
start for you.

HTH,

Joseph W.
http://blog.josephwilk.net


#7

Joseph W. wrote:

I don’t think this is the case. Every Before/After that is in a required
file is run before a scenario. So in theory you could create one Before
(in for example env.rb) which would get called for all scenarios.

I experimented with the following code in env.rb, borrowing heavily from
the discussion on ticker 44 and this is what happened:

Before do |scenario|
logger.info(“Running Scenario: #{scenario}”)
end

Scenario: Record Entity basic identification information #
features/entities/entity.feature:12
/usr/lib/ruby/gems/1.8/gems/cucumber-0.1.9/bin/…/lib/cucumber/core_ext/proc.rb:15:in
call_in': expected 1 block argument(s), got 0 (Cucumber::ArityMismatchError) from /usr/lib/ruby/gems/1.8/gems/cucumber-0.1.9/bin/../lib/cucumber/executor.rb:91:inexecute_scenario’


#8

James B. wrote:

Joseph W. wrote:

I don’t think this is the case. Every Before/After that is in a required
file is run before a scenario. So in theory you could create one Before
(in for example env.rb) which would get called for all scenarios.

I experimented with the following code in env.rb, borrowing heavily from
the discussion on ticker 44 and this is what happened:

Before do |scenario|
logger.info(“Running Scenario: #{scenario}”)
end

The patch that you are referring to in ticket #44 has not been merged
in. So passing a block to scenario is not currently possible.


Joseph W.
http://blog.josephwilk.net

Scenario: Record Entity basic identification information #
features/entities/entity.feature:12
/usr/lib/ruby/gems/1.8/gems/cucumber-0.1.9/bin/…/lib/cucumber/core_ext/proc.rb:15:in
call_in': expected 1 block argument(s), got 0 (Cucumber::ArityMismatchError) from /usr/lib/ruby/gems/1.8/gems/cucumber-0.1.9/bin/../lib/cucumber/executor.rb:91:inexecute_scenario’


#9

James B. wrote:

logger.info(“Running Scenario: #{scenario}”

logger.info(" Running Step: #{step}"

should be:

logger.info(“Running Scenario: #{scenario}”)

and

logger.info(" Running Step: #{step}")