Skip to content

Commit

Permalink
Adds more tests for matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
philostler committed May 15, 2013
1 parent 5f53322 commit a36d3e3
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/rspec/sidekiq/matchers/be_retryable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def failure_message
end

def matches? job
@klass = job.class
@klass = job.kind_of?(Class) ? job : job.class
@actual = @klass.get_sidekiq_options["retry"]
@actual == @expected
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/sidekiq/matchers/be_unique.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def failure_message
end

def matches? job
@klass = job.class
@klass = job.kind_of?(Class) ? job : job.class
@actual = @klass.get_sidekiq_options["unique"]
@actual == true
end
Expand Down
41 changes: 41 additions & 0 deletions spec/rspec/sidekiq/matchers/be_retryable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require "spec_helper"

describe "Be Retryable matcher" do

describe "expect syntax" do
context "when retryable is number" do
it "correctly matches" do
expect(TestWorker).to be_retryable 5
end
end

context "when retryable is true" do
it "correctly matches" do
expect(TestWorkerDefaults).to be_retryable true
end
end

context "when retryable is false" do
it "correctly matches" do
expect(TestWorkerAlternative).to be_retryable false
end
end
end

describe "one liner syntax" do
context "when retryable is number" do
subject { TestWorker }
expect_it { to be_retryable 5 }
end

context "when retryable is true" do
subject { TestWorkerDefaults }
expect_it { to be_retryable true }
end

context "when retryable is false" do
subject { TestWorkerAlternative }
expect_it { to be_retryable false }
end
end
end
15 changes: 15 additions & 0 deletions spec/rspec/sidekiq/matchers/be_unique_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "spec_helper"

describe "Be Unique matcher" do
subject { TestWorker }

describe "expect syntax" do
it "correctly matches" do
expect(TestWorker).to be_unique
end
end

describe "one liner syntax" do
expect_it { to be_unique }
end
end
4 changes: 3 additions & 1 deletion spec/support/init.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
require_relative "test_worker"
require_relative "test_worker"
require_relative "test_worker_alternative"
require_relative "test_worker_defaults"
2 changes: 1 addition & 1 deletion spec/support/test_worker.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class TestWorker
include Sidekiq::Worker

sidekiq_options queue: :data
sidekiq_options queue: :data, retry: 5, unique: true

def perform
end
Expand Down
8 changes: 8 additions & 0 deletions spec/support/test_worker_alternative.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class TestWorkerAlternative
include Sidekiq::Worker

sidekiq_options queue: "data", retry: false, unique: false

def perform
end
end
6 changes: 6 additions & 0 deletions spec/support/test_worker_defaults.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class TestWorkerDefaults
include Sidekiq::Worker

def perform
end
end

0 comments on commit a36d3e3

Please sign in to comment.