Project

cmdx-rspec

0.0
No release in over 3 years
Simple CMDx task testing via RSpec matchers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

>= 1.5.0
>= 0
 Project Readme
CMDx Logo CMDx Logo

Collection of RSpec matchers for the CMDx framework.

Changelog · Report Bug · Request Feature

Version Build License

CMDx::RSpec

Collection of RSpec matchers for CMDx.

Installation

Add this line to your application's Gemfile:

gem 'cmdx-rspec'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cmdx-rspec

Matchers

be_successful

Asserts that a CMDx task result indicates successful execution.

it "returns success" do
  result = SomeTask.execute

  expect(result).to be_successful
end

have_skipped

Asserts that a CMDx task result indicates the task was skipped during execution.

it "returns skipped" do
  result = SomeTask.execute

  # Default result
  expect(result).to have_skipped

  # Custom result
  expect(result).to have_skipped(
    reason: "Skipping for a custom reason",
    cause: be_a(CMDx::SkipFault)
    # Other members of `result.to_h`...
  )
end

have_failed

Asserts that a CMDx task result indicates execution failure.

it "returns failure" do
  result = SomeTask.execute

  # Default result
  expect(result).to have_failed

  # Custom result
  expect(result).to have_failed(
    reason: "Failed for a custom reason",
    cause: be_a(NoMethodError)
    # Other members of `result.to_h`...
  )
end

have_empty_metadata

Asserts that a CMDx task result has no metadata.

it "returns empty metadata" do
  result = SomeTask.execute

  expect(result).to have_empty_metadata
end

have_matching_metadata

Asserts that a CMDx task result contains specific metadata.

it "returns matching metadata" do
  result = SomeTask.execute

  expect(result).to have_matching_metadata(status_code: 500)
end

have_empty_context

Asserts that a CMDx task result has no context data.

it "returns empty context" do
  result = SomeTask.execute

  expect(result).to have_empty_context
end

have_matching_context

Asserts that a CMDx task result contains specific context data.

it "returns matching context" do
  result = SomeTask.execute

  expect(result).to have_matching_context(stored_result: 123)
end

be_deprecated

Asserts that a CMDx task result indicates the task is deprecated.

it "returns deprecated" do
  expect(SomeTask).to be_deprecated
end

Helpers

Including Helper Modules

Include the helper modules in your RSpec configuration or example groups:

RSpec.configure do |config|
  config.include CMDx::RSpec::Helpers
end

Or include them in specific example groups:

describe MyFeature do
  include CMDx::RSpec::Helpers

  # Your specs...
end

Stubs

Helper methods for stubbing CMDx command execution.

Types

it "stubs task executions by type" do
  # eg: SomeTask.execute
  stub_task_success(SomeTask)
  stub_task_skip(SomeTask)
  stub_task_fail(SomeTask)

  # eg: SomeTask.execute!
  stub_task_success!(SomeTask)
  stub_task_skip!(SomeTask)
  stub_task_fail!(SomeTask)

  # Your specs...
end

it "stubs task with arguments" do
  # eg: SomeTask.execute(some: "value")
  stub_task_success(SomeTask, some: "value")

  # eg: SomeTask.execute!(some: "value")
  stub_task_skip!(SomeTask, some: "value")

  # Your specs...
end

Options

it "stubs task with metadata" do
  stub_task_success(SomeTask, metadata: { some: "value" })

  # Your specs...
end

it "stubs task with a custom reason" do
  stub_task_skip!(SomeTask, reason: "Skipping for a custom reason")

  # Your specs...
end

it "stubs task with a custom cause" do
  stub_task_fail!(SomeTask, cause: NoMethodError.new("just blow it up"))

  # Your specs...
end

Reset

it "unstubs task executions by type" do
  # eg: SomeTask.execute
  unstub_task(SomeTask)

  # eg: SomeTask.execute!
  unstub_task!(SomeTask)

  # Your specs...
end

it "unstubs task with arguments" do
  # eg: SomeTask.execute(some: "value")
  unstub_task(SomeTask, some: "value")

  # eg: SomeTask.execute!(some: "value")
  unstub_task!(SomeTask, some: "value")

  # Your specs...
end

Mocks

Helper methods for setting expectations on CMDx command execution.

Types

it "mocks task executions by type" do
  # eg: SomeTask.execute
  expect_task_execution(SomeTask)
  expect_no_task_execution(SomeTask)

  # eg: SomeTask.execute!
  expect_task_execution!(BangCommand)
  expect_no_task_execution!(SomeTask)

  # Your specs...
end

it "mocks task with arguments" do
  # eg: SomeTask.execute(some: "value")
  expect_task_execution(SomeTask, some: "value")
  expect_no_task_execution(SomeTask, some: "value")

  # eg: SomeTask.execute!(some: "value")
  expect_task_execution!(SomeTask, some: "value")
  expect_no_task_execution!(SomeTask, some: "value")

  # Your specs...
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/drexed/cmdx-rspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Cmdx::Rspec project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.