In Cucumber on Ruby w/rspec, how do I expect/assert a webmocked call in a Then clause? -


i'm writing gem acts client remote api, i'm using webmock mock out remote api, testing cucumber rspec-mock present too.

as part of cucumber tests intend stub api in given clause specify remote api called in then clause.

a basic example be:

feature file

scenario: doing triggers call   given have mocked google   when call library   calls google stub   , response library 

step definition

given /i have mocked api/   stub_request(:get, 'www.google.com') end  when /i call library/   mylibrary.call_google_for_some_reason end  /it calls google stub/   # somehow test here end 

the question: how can verify google stub has been called?

side note: i'm aware use expect(a_request(...)) or expect(webmock).to ... syntax feeling i'll repeating what's defined in given clause.

i answer myself, though verify correct and/or has no major pitfalls:

given /i have mocked api/   @request = stub_request(:get, 'www.google.com') end  /it calls google stub/   expect(@request).to have_been_made.once end 

the bits note assignment of @request , expectation placed upon in then clause.

in limited test of 2 separate scenarios approach seems work.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -