On Saturday, April 21, 2012 at 11:35 PM, Pin Xie wrote:
> Hi,
>  
> I am working some test scripts with rspec, I try to pend example, once
> user input is not supported. However, the result is not what I
> expected pending example, instead of exception - "NameError: undefined
> local variable or method `example'"
>  
> I know pending method works inside of describe block, but my question
> is how pending method work outside of rspec example, just like should
> method?
>  
> Thanks.
>  
> source code is enclosed.
> ## harness.rb
> require "rspec"
> class Harness
> include RSpec::Core::Pending
>  
> def get_fruit(fruit_name)
> pending "your input #{fruit_name} does not supported yet!" unless
> get_supported_fruits().include?(fruit_name)
> create(fruit_name)
> end
> end
>  
> # fruit_spec.rb
> require "harness"
> describe "create fruit" do
> it "create pineapple" do
> harness = Harness.new
> fruit = harness.get_fruit("pineapple")
> end
> end
>  
>  

The `Pending` module is intended to be used outside of `ExampleGroup`, which is 
where the `example` method is defined. I realize it's a separate module, but it 
is not intended to be a public API.

I'd just define `get_fruit` right in the group where it's being used, or in a 
module included into all groups using `config.before`:

  describe Something do
    def get_fruit(…); …; end
   
    it "does something" do
      # …
    end
  end

or …..

  module FruitHelpers
    def get_fruit(…); …; end
  end
   
  RSpec.configure {|c| c.include FruitHelpers}

HTH,
David

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rspec?hl=en.

Reply via email to