https://pact.io logo
#pact-ruby
Title
# pact-ruby
k

Kellie Persson

09/23/2022, 6:13 PM
Hello Everyone 👋 , I am testing out PACT w/ pact-swift and a docker image pact-broker. I have been able to publish my pact to the pact broker and now am trying to verify the pact from the provider side of things (ruby). On the provider side I am setting up my provider states but I am having a tough time getting any gem dependencies to load, i.e. using
circumstance-1.0.0
gem to setup state for me. Do I need to do any special setup to gain access to these gems inside the provider state files? Thank you for you helpful. Excited to get this POC going.
b

Beth (pactflow.io/Pact Broker/pact-ruby)

09/27/2022, 12:53 AM
Can you share your code @Kellie Persson?
You should just be able to require anything in the provider state file.
Have you got an explicit
require "…"
?
k

Kellie Persson

09/27/2022, 2:15 AM
Hello @Beth (pactflow.io/Pact Broker/pact-ruby) Thank you for the reply. I was able to get past the issue by making use of
Copy code
Pact.configure do | config |
  config.include ::Circumstance::Helpers
end
in my
pact_helper.rb
file.
b

Beth (pactflow.io/Pact Broker/pact-ruby)

09/27/2022, 6:36 AM
Great!
k

Kellie Persson

09/27/2022, 4:29 PM
@Beth (pactflow.io/Pact Broker/pact-ruby), I have a followup question. It appears that
let
statements are not allowed in the provider state
set_up
do block E.g.
Copy code
provider_state "default" do
    set_up do
      load_circumstance :data
    end
end
under the hood, in the
data
circumstance loads another circumstance,
Copy code
Circumstance.define(:data) do
  load_circumstance :base
end
in this circumstance 😅 , the following let statement is used:
Copy code
Circumstance.define(:base) do
  let(:level) { Level.find(1) }
end
it is this ⬆️
let
statement that seems to be causing the following error when trying to validate.
Copy code
Failure/Error: let(:level) { Level.find(1) }

NoMethodError:
       undefined method `let' for #<Pact::Provider::State::ProviderState:0x00007f854b79c7c8>
I am a ruby novice, but I believe let can only be defined in ruby
describe
blocks. Is there any way around this error that I am seeing. I am trying to minimize the setup code by using previously defined circumstances that are used in our other RSpec tests. Thank you for any help or direction you can provide. Let me know if you need additional information.
b

Beth (pactflow.io/Pact Broker/pact-ruby)

09/28/2022, 1:18 AM
let
is an rspec feature. You can only use plain ruby inside the provider state blocks.
level = Level.find(1)
k

Kellie Persson

09/28/2022, 1:20 AM
Gotcha. Will look to clean things up on my end to use plain ruby. Thanks so much for your help.
6 Views