Skip to content

Commit

Permalink
Make requiring RSpec explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Oct 24, 2017
1 parent d54c209 commit 655897d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,24 @@ end

### RSpec Usage

First, you need to have [rspec-rails](https://github.com/rspec/rspec-rails) installed.

First, set your adapter to `test` in `cable.yml`:
Second, add this to your `"rails_helper.rb"` after requiring `environment.rb`:

```ruby
require "action_cable/testing/rspec"
```

To use `have_broadcasted_to` / `broadcast_to` matchers anywhere in your specs, set your adapter to `test` in `cable.yml`:

```yml
# config/cable.yml
test:
adapter: test
```
Now you can use `have_broadcasted_to` / `broadcast_to` matchers anywhere in your specs. For example:
And then use these matchers, for example:
```ruby
RSpec.describe CommentsController do
Expand Down
12 changes: 10 additions & 2 deletions features/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ And then execute:

## Basic Usage

First, set your adapter to `test` in `cable.yml`:
First, you need to have [rspec-rails](https://github.com/rspec/rspec-rails) installed.

Second, add this to your `"rails_helper.rb"` after requiring `environment.rb`:

```ruby
require "action_cable/testing/rspec"
```

To use `have_broadcasted_to` / `broadcast_to` matchers anywhere in your specs, set your adapter to `test` in `cable.yml`:

```yml
# config/cable.yml
test:
adapter: test
```
Now you can use `have_broadcasted_to` / `broadcast_to` matchers anywhere in your specs. For example:
And then use these matchers, for example:
```ruby
RSpec.describe CommentsController do
Expand Down
4 changes: 1 addition & 3 deletions features/step_definitions/additional_cli_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
end

require "rails/version"

require "rspec/rails"
require "action-cable-testing"
require "action_cable/testing/rspec"

Then /^the example(s)? should( all)? pass$/ do |_, _|
step %q{the output should contain "0 failures"}
Expand Down
2 changes: 0 additions & 2 deletions lib/action_cable/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@ module SubscriptionAdapter
autoload :Test
end
end

require "action_cable/testing/rspec" if defined?(::RSpec::Rails)
2 changes: 2 additions & 0 deletions lib/action_cable/testing/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "action-cable-testing"
require "rspec/rails"
require "rspec/rails/example/channel_example_group"
require "rspec/rails/matchers/action_cable"

Expand Down
3 changes: 1 addition & 2 deletions spec/dummy/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require 'action-cable-testing'
require "action_cable/testing/rspec"

# Add additional requires below this line. Rails is not loaded until this point!

Expand Down
4 changes: 1 addition & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
require "action_view/railtie"
require "action_cable"

require "rspec/rails"

require "action-cable-testing"
require "action_cable/testing/rspec"

require "ammeter/init"

Expand Down

0 comments on commit 655897d

Please sign in to comment.