Coder Social home page Coder Social logo

how to test with rspec? about simple_command HOT 2 CLOSED

nebulab avatar nebulab commented on July 23, 2024
how to test with rspec?

from simple_command.

Comments (2)

kennyadsl avatar kennyadsl commented on July 23, 2024 1

@thg303 Hi there, thanks for using this gem.

Suppose to have a command like:

class MyCommand
  prepend SimpleCommand

  def initialize(something)
    @something = something
  end

  def call
    if @something == :ok
      return
    else
      errors.add(:something, 'Something Wrong')
    end
    nil
  end
end

You can create a spec similar to this one:

describe MyCommand do
  subject(:context) { described_class.call(something) }

  describe '.call' do
    context 'when the context is successful' do
      let(:something) { :ok }

      it 'succeeds' do
        expect(context).to be_success
      end
    end

    context 'when the context is not successful' do
      let(:something) { :wrong }

      it 'fails' do
        expect(context).to be_failure
      end
    end
  end
end

If this works and you want to contribute, feel free to open a PR with something about using it with RSpec in the README, thanks!

from simple_command.

thg303 avatar thg303 commented on July 23, 2024

it worked. thanks. I submitted a PR for this

from simple_command.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.