Sha256: b50508eac34ef5c667e5340ecad913d6abd7c94527ad8ef599f1fcb0b0ab9391

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

RSpec::Matchers.define :be_listable_resource do |expected|
  match do |actual|
    client = authorized_civicrm_client
    subject = actual.class
    test_response_hash = send(:"test_#{subject.name.demodulize.underscore}_array")

    expect(client).
      to receive(:get).
          exactly(:once).
          and_return(test_response(test_response_hash))

    expect(subject.all).to be_a_kind_of(Array)
  end
end

RSpec::Matchers.define :be_updatable_resource do |expected|
  match do |actual|
    client = authorized_civicrm_client
    subject = actual.class

    expect(client).
      to receive(:get).
          exactly(:once).
          and_return(test_response(test_contact({name: "foo"})))

    expect(client).
      to receive(:put).
          exactly(:once).
          and_return(test_response(test_contact({name: "bar"})))

    c = subject.find("resource_id")
    expect(c.name).to eq("foo")

    c.name = "bar"
    c.save
    expect(c.name).to eq("bar")
  end
end

RSpec::Matchers.define :be_deleteable_resource do |expected|
  match do |actual|
    client = authorized_civicrm_client
    subject = actual.class

    expect(client).
      to receive(:get).
          exactly(:once).
          and_return(test_response(test_contact({name: "foo"})))

    expect(client).
      to receive(:delete).
          exactly(:once).
          and_return(test_response(test_contact({name: "bar"})))

    c = subject.find("resource_id")
    c.delete
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
civicrm-1.1.1 spec/support/test_matchers.rb
civicrm-1.1.0 spec/support/test_matchers.rb
civicrm-1.0.7 spec/support/test_matchers.rb
civicrm-1.0.6 spec/support/test_matchers.rb