Skip to content

Commit

Permalink
Add rspec tests to ScheduledExecutor and FeatureToggle#Variant
Browse files Browse the repository at this point in the history
  • Loading branch information
rarruda committed Nov 21, 2019
1 parent e4f12db commit b1201fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spec/unleash/feature_toggle_spec.rb
Expand Up @@ -406,4 +406,31 @@
)
end
end

describe 'FeatureToggle with invalid default_variant' do
let(:feature_toggle) do
Unleash::FeatureToggle.new(
"name" => "Test.variants",
"description" => nil,
"enabled" => true,
"strategies" => [
{
"name" => "default"
}
],
"variants" => [],
"createdAt" => "2019-01-24T10:41:45.236Z"
)
end
let(:valid_default_variant) { Unleash::Variant.new(name: 'unknown', default: true) }
let(:invalid_default_variant) { Hash.new(name: 'unknown', default: true) }

it 'should raise an error for an invalid fallback variant' do
expect{ feature_toggle.get_variant(nil, invalid_default_variant) }.to raise_error(ArgumentError)
end

it 'should not raise an error for a valid fallback variant' do
expect{ feature_toggle.get_variant(nil, valid_default_variant) }.to_not raise_error(ArgumentError)
end
end
end
16 changes: 16 additions & 0 deletions spec/unleash/scheduled_executor_spec.rb
Expand Up @@ -14,4 +14,20 @@
scheduled_executor.exit
expect(scheduled_executor.running?).to be false
end

# Test that it will correctly stop running after the provided number of exceptions
it "will stop running after the configured number of failures" do
max_exceptions = 2

scheduled_executor = Unleash::ScheduledExecutor.new('TesterLoop', 0, max_exceptions)
scheduled_executor.run do
raise StopIteration
end
expect(scheduled_executor.thread).to_not be_nil

scheduled_executor.thread.join

expect(scheduled_executor.retry_count).to be == 1 + max_exceptions
expect(scheduled_executor.running?).to be false
end
end

0 comments on commit b1201fc

Please sign in to comment.