Logo: Relish

  1. Sign in

Project: Shokkenki-provider 0.0.4

Defining fixtures

A consumer specifies a fixture and supplies parameters but it is up to the provider to implement the fulfilment of each fixture.

Each fixture required within a consumer ticket will need to be fulfilled. Fixtures are defined using a regex, allowing them to match non-exact specified fixture names. The MatchData instance is also made available to the fixture definition.

Fixture definitions can be paired with blueprint tools like Machinist or Factory Girl to establish data easily.

Scenarios
Define a provider fixture with standard arguments
Given
a ticket named "tickets/consumer-provider.json" including the following interaction:
{
  "label": "greeting",
  "request": {
    "type": "hash",
    "value": {
      "path": {
        "type": "string",
        "value": "/weather"
      },
      "method": {
        "type": "string",
        "value": "get"
      }
    }
  },
  "response": {
    "type": "hash",
    "value": {
      "status": {
        "type": "number",
        "value": 200
      }
    }
  },
  "fixtures": [
    {
      "name": "greeter exists",
      "arguments": {
        "mood": "happy"
      }
    }
  ]
}
And
a file named "spec/provider.spec" with:
provider = lambda do |env|
  [200, {}, ['']]
end

Shokkenki.provider.configure do
  provider :provider do
    run provider

    given /greeter exists/ do |args|
      puts "Mood is #{args[:arguments][:mood]}"
    end
  end
end

Shokkenki.provider.redeem_tickets
When
I run rspec --format documentation
Then
all examples should pass
And
the output should contain:
Mood is happy
Define a provider fixture and use regex matchdata
Given
a ticket named "tickets/consumer-provider.json" including the following interaction:
{
  "label": "greeting",
  "request": {
    "type": "hash",
    "value": {
      "path": {
        "type": "string",
        "value": "/weather"
      },
      "method": {
        "type": "string",
        "value": "get"
      }
    }
  },
  "response": {
    "type": "hash",
    "value": {
      "status": {
        "type": "number",
        "value": 200
      }
    }
  },
  "fixtures": [
    {
      "name": "greeter exists that is happy"
    }
  ]
}
And
a file named "spec/provider.spec" with:
provider = lambda do |env|
  [200, {}, ['']]
end

Shokkenki.provider.configure do
  provider :provider do
    run provider

    given /greeter exists that is (.*)/ do |args|
      puts "Mood is #{args[:match][1]}"
    end
  end
end

Shokkenki.provider.redeem_tickets
When
I run rspec --format documentation
Then
all examples should pass
And
the output should contain:
Mood is happy

Last published about 5 years ago by brentsnook.