All Projects → krisleech → wisper-rspec

krisleech / wisper-rspec

Licence: MIT license
RSpec matchers and stubbing for Wisper

Programming Languages

ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to wisper-rspec

capybara-chrome
Chrome driver for Capybara using Chrome's remote debugging protocol
Stars: ✭ 27 (-54.24%)
Mutual labels:  rspec
serverspec-extended-types
A set of extended types for ServerSpec 2.x
Stars: ✭ 28 (-52.54%)
Mutual labels:  rspec
mache
A library for writing cleaner and more expressive acceptance tests using page objects.
Stars: ✭ 40 (-32.2%)
Mutual labels:  rspec
rspec html reporter
Rspec custom formatter to produce beautiful reports from rspec
Stars: ✭ 32 (-45.76%)
Mutual labels:  rspec
capybara-chromedriver-logger
Enables console.log/error/info output from Javascript feature specs running with Chromedriver
Stars: ✭ 54 (-8.47%)
Mutual labels:  rspec
r spec-clone.rb
A minimalist RSpec clone with all the essentials.
Stars: ✭ 38 (-35.59%)
Mutual labels:  rspec
Nspec
A battle hardened testing framework for C# that's heavily inspired by Mocha and RSpec.
Stars: ✭ 242 (+310.17%)
Mutual labels:  rspec
bdd
Given/When/Then/And/But output to RSpec and Minitest
Stars: ✭ 33 (-44.07%)
Mutual labels:  rspec
j8spec
Library that allows tests written in Java to follow the BDD style introduced by RSpec and Jasmine.
Stars: ✭ 45 (-23.73%)
Mutual labels:  rspec
turbo tests
Run RSpec tests on multiple cores. Like parallel_tests but with incremental summarized output. Originally extracted from the Discourse and Rubygems source code.
Stars: ✭ 81 (+37.29%)
Mutual labels:  rspec
opal-rspec
Opal + RSpec = ♥️
Stars: ✭ 57 (-3.39%)
Mutual labels:  rspec
house style
A shared house style for Ruby projects
Stars: ✭ 19 (-67.8%)
Mutual labels:  rspec
rspec-tap-formatters
TAP Producer for RSpec-3
Stars: ✭ 20 (-66.1%)
Mutual labels:  rspec
full-stack-web-developer
🔥 Roadmap to become a Full Stack Web Developer. What? Why? How?
Stars: ✭ 76 (+28.81%)
Mutual labels:  rspec
database plumber
Find leaky ActiveRecord models in your RSpec tests
Stars: ✭ 13 (-77.97%)
Mutual labels:  rspec
Apitome
Apitome: /iˈpitəmē/ An API documentation presentation layer for RSpec API Documentation output.
Stars: ✭ 244 (+313.56%)
Mutual labels:  rspec
solr wrapper
Wrap your tests with Solr 5+
Stars: ✭ 22 (-62.71%)
Mutual labels:  rspec
ginkgo4j
A Java BDD Testing Framework (based on RSpec and Ginkgo)
Stars: ✭ 25 (-57.63%)
Mutual labels:  rspec
givens
Easy test setup without side effects.
Stars: ✭ 22 (-62.71%)
Mutual labels:  rspec
saharspec
RSpec sugar to DRY your specs
Stars: ✭ 58 (-1.69%)
Mutual labels:  rspec

Wisper::Rspec

Rspec matcher and stubbing for Wisper.

Gem Version Build Status

Installation

gem 'wisper-rspec', require: false

Usage

Broadcast Matcher

In spec_helper

require 'wisper/rspec/matchers'

RSpec::configure do |config|
  config.include(Wisper::RSpec::BroadcastMatcher)
end

In your specs:

expect { publisher.execute }.to broadcast(:an_event)

This will match both broadcast(:an_event) and broadcast(:an_event, :arg_1).

# with optional arguments
expect { publisher.execute }.to broadcast(:another_event, :arg_1, :arg_2)

With event arguments, it matches only if the event is broadcast with those arguments. This assertion matches broadcast(:another_event, :arg_1, :arg_2) but not broadcast(:another_event).

# with arguments matcher
expect { publisher.execute }.to broadcast(:event, hash_including(a: 2))

Rspec values matcher can be used to match arguments. This assertion matches broadcast(:another_event, a: 2, b: 1) but not broadcast(:another_event, a: 3)

Matchers can be composed using compound rspec matchers:

expect {
  publisher.execute(123)
  publisher.execute(234)
}.to broadcast(:event, 123).and broadcast(:event, 234)

expect {
  publisher.execute(123)
  publisher.execute(234)
}.to broadcast(:event, 123).or broadcast(:event, 234)

Note that the broadcast method is aliased as publish, similar to the Wisper library itself.

Not broadcast matcher

If you want to assert a broadcast was not made you can use not_broadcast which is especially useful when chaining expectations.

expect {
  publisher.execute(123)
}.to not_broadcast(:event, 99).and broadcast(:event, 123)

Using message expectations

If you need to assert on the listener receiving broadcast arguments you can subscribe a double with a message expectation and then use any of the argument matchers.

listener = double('Listener')

expect(listener).to receive(:an_event).with(some_args)

publisher.subscribe(listener)

publisher.execute

Stubbing publishers

You can stub publishers and their events in unit (isolated) tests that only care about reacting to events.

Given this piece of code:

class MyController
  def create
    publisher = MyPublisher.new

    publisher.on(:some_event) do |variable|
      return "Hello with #{variable}!"
    end

    publisher.execute
  end
end

You can test it like this:

require 'wisper/rspec/stub_wisper_publisher'

describe MyController do
  context "on some_event" do
    before do
      stub_wisper_publisher("MyPublisher", :execute, :some_event, "foo")
    end

    it "renders" do
      response = MyController.new.create
      expect(response).to eq "Hello with foo!"
    end
  end
end

This is useful when testing Rails controllers in isolation from the business logic.

You can use any number of args to pass to the event:

stub_wisper_publisher("MyPublisher", :execute, :some_event, "foo1", "foo2", ...)

See spec/lib/rspec_extensions_spec.rb for a runnable example.

Contributing

Yes, please.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].