Forum: RSpec Cucumber Custom Logging

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2008-11-24 20:40
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
    ....
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 aslak hellesoy (Guest)
on 2008-11-24 20:58
(Received via mailing list)
On Mon, Nov 24, 2008 at 8:40 PM, James Byrne <lists@ruby-forum.com>
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?
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2008-11-24 21:00
aslak hellesoy wrote:
> On Mon, Nov 24, 2008 at 8:40 PM, James Byrne <lists@ruby-forum.com>
> 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
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 aslak hellesoy (Guest)
on 2008-11-24 21:06
(Received via mailing list)
On Mon, Nov 24, 2008 at 9:00 PM, James Byrne <lists@ruby-forum.com>
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
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2008-11-24 21:35
aslak hellesoy wrote:
> On Mon, Nov 24, 2008 at 9:00 PM, James Byrne <lists@ruby-forum.com>
> 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/tick...

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.
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2008-11-24 21:39
James Byrne wrote:

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

should be:

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

and

 logger.info("    Running Step: #{step}")
3c28deaff162aeda44f2e0bcdca1dacf?d=identicon&s=25 Joseph Wilk (josephwilk)
on 2008-11-24 22:01
>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 Wilk
http://blog.josephwilk.net
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2008-11-24 22:26
Joseph Wilk 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:in
`execute_scenario'
3c28deaff162aeda44f2e0bcdca1dacf?d=identicon&s=25 Joseph Wilk (josephwilk)
on 2008-11-25 12:57
James Byrne wrote:
> Joseph Wilk 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 Wilk
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:in
> `execute_scenario'
This topic is locked and can not be replied to.