0

I'm trying to move my Cucumber Matcher into a function of a module

Then (/^posted "(.*?)" http response should be returned$/) do |arg1|
  expect($post_result.lines.last.to_i).to eq(arg1.to_i)
end

The module function as below

module AccessFunc
    #  :
    #  : Some require... global variable setting etc
    #  :
  def self.posted_http_response_check(arg1)
    expect($post_result.lines.last.to_i).to eq(arg1.to_i)
  end
end

Running my cucumber test with the cucumber matcher could use the Expect. But I can't use the Expect within my module. I tried using

include ::RSpec::Matchers

as per Use RSpec's "expect" etc. outside a describe ... it block but not successful.

The error I got is

undefined method `expect' for AccessFunc:Module (NoMethodError)

Could someone shed some light how could I workaround this (e.g. using Expect within a Module.

p/s: I could solve the problem by remove the Module, and define the function posted_http_response_check globally.

Community
  • 1
  • 1
Elye
  • 53,639
  • 54
  • 212
  • 474
  • is this a piece of test ? if not why do you need an expect in a module . – AshwinKumarS Mar 25 '15 at 07:03
  • Yes, this is one part of test. I'm moving this expect into a module, it's because I plan to use it is various different test scenarios, and hence don't want to have it repeated over the Cucumber Matcher. – Elye Mar 25 '15 at 10:05

1 Answers1

0

You may have to mixin the AccessFunc module, for the scenario steps to recognize this.
Try adding World AccessFunc to your env.rb and see how it goes. Can't say for sure if this will work, definitely worth a try though.

roonie
  • 136
  • 1
  • 5