diaspora_federation/spec/lib/diaspora_federation/callbacks_spec.rb
Benjamin Neff e26a86c173
Switch PercentLiteralDelimiters to new default
Let's change that to the new rubocop default, which is also the
suggestion in the ruby style guide.

See https://github.com/bbatsov/ruby-style-guide#percent-literal-braces

This was changed in diaspora too, see diaspora/diaspora#7466

It also includes the changes in the code. This was done with
`rubocop --auto-correct` and no we have zero offenses again.
2017-06-30 02:23:44 +02:00

74 lines
2.3 KiB
Ruby

module DiasporaFederation
describe Callbacks do
subject(:callbacks) { Callbacks.new %i[some_event another_event] }
context "callbacks" do
it "defines a callback and calls it" do
callbacks.on(:some_event) do
"result"
end
expect(callbacks.trigger(:some_event)).to eq("result")
end
it "defines a callback with params and calls it" do
callbacks.on(:some_event) do |arg1, arg2|
"result: #{arg1}, #{arg2}"
end
expect(callbacks.trigger(:some_event, "foo", "bar")).to eq("result: foo, bar")
end
end
describe "#on" do
it "fails if an event is unknown" do
expect { callbacks.on(:unknown_event) {} }.to raise_error ArgumentError, "Undefined event unknown_event"
end
it "fails if an event is unknown" do
callbacks.on(:some_event) {}
expect { callbacks.on(:some_event) {} }.to raise_error ArgumentError, "Already defined event some_event"
end
end
describe "#trigger" do
it "fails if an event is unknown" do
expect { callbacks.trigger(:unknown_event) }.to raise_error ArgumentError, "Undefined event unknown_event"
end
end
describe "#definition_complete?" do
it "is false if nothing is defined" do
expect(callbacks.definition_complete?).to be_falsey
end
it "is false if not all events are defined" do
callbacks.on(:some_event) {}
expect(callbacks.definition_complete?).to be_falsey
end
it "is true if all events are defined" do
callbacks.on(:some_event) {}
callbacks.on(:another_event) {}
expect(callbacks.definition_complete?).to be_truthy
end
end
describe "#missing_handlers" do
it "contains all events if nothing isdefined" do
expect(callbacks.missing_handlers).to eq(%i[some_event another_event])
end
it "contains the missing events if not all events are defined" do
callbacks.on(:some_event) {}
expect(callbacks.missing_handlers).to eq(%i[another_event])
end
it "is empty if all events are defined" do
callbacks.on(:some_event) {}
callbacks.on(:another_event) {}
expect(callbacks.missing_handlers).to be_empty
end
end
end
end