Is it possible to extract data in Expect matcher?

54 views
Skip to first unread message

jeane

unread,
Jul 14, 2014, 9:16:45 PM7/14/14
to rs...@googlegroups.com
Greetings,

Im in a project and my task is to extract what is being evaluated in Rspec Expect matcher. 

I was able to extract data from Factorygirl by using a callback and output data to an Excel File.

But now, they wanted me to extract Expect. I know there are lots of things going on to expect. 

is it possible to attach a callback or extend the Expect matcher in Rspec?

Thank you in advance!

Myron Marston

unread,
Jul 15, 2014, 2:11:14 AM7/15/14
to rs...@googlegroups.com
module ExpectHook
  def expect(*args, &block)
    puts "your logic here"
    super
  end
end

RSpec.configure do |config|
  config.include ExpectHook
end
 

jeane

unread,
Jul 15, 2014, 3:10:33 AM7/15/14
to rs...@googlegroups.com
Greetings,

oh! this is a big help! somehow i could args or block in results from expect! this could be a good start. thank you!

jeane

unread,
Jul 17, 2014, 11:12:11 PM7/17/14
to rs...@googlegroups.com
Greetings,

I have accomplished extracting some data from expect. thanks for the help.. but now, I need to get the expect string.. I mean the whole line of expect statement.. and place it together with the extracted data..

I know I am asking too much, but I have tried some ways I can come up, like reading and matching the whole spec file, for expect string and put them on a list. but where to place it and when to place it, Is my problem.

it would be nice if
module ExpectHook
  def expect(*args, &block)
    puts "your logic here"
    puts expect.name #or something like this?
    my_method(args, expect.name) #extraction method to output in excel file
    super
  end
end

thank you once again..

Myron Marston

unread,
Jul 22, 2014, 11:36:43 AM7/22/14
to rs...@googlegroups.com
What do you mean by the "expect string"?  Can you post an example spec and what you want to extract from it?
Reply all
Reply to author
Forward
0 new messages