Skip to content

Commit

Permalink
Add #without_feature, it is used by MJIT in Ruby trunk currently
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jun 27, 2018
1 parent b17a384 commit 7074b56
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mspec/guards/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ def match?
def with_feature(*features, &block)
FeatureGuard.new(*features).run_if(:with_feature, &block)
end

def without_feature(*features, &block)
FeatureGuard.new(*features).run_unless(:without_feature, &block)
end
40 changes: 40 additions & 0 deletions spec/guards/feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,43 @@
ScratchPad.recorded.should be_nil
end
end

describe Object, "#without_feature" do
before :each do
ScratchPad.clear

@guard = FeatureGuard.new :encoding
FeatureGuard.stub(:new).and_return(@guard)
end

it "sets the name of the guard to :without_feature" do
without_feature(:encoding) { }
@guard.name.should == :without_feature
end

it "calls #unregister even when an exception is raised in the guard block" do
@guard.should_receive(:match?).and_return(false)
@guard.should_receive(:unregister)
lambda do
without_feature { raise Exception }
end.should raise_error(Exception)
end
end

describe Object, "#without_feature" do
before :each do
ScratchPad.clear
end

it "does not yield if the feature is enabled" do
MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(true)
without_feature(:encoding) { ScratchPad.record :yield }
ScratchPad.recorded.should be_nil
end

it "yields if the feature is disabled" do
MSpec.should_receive(:feature_enabled?).with(:encoding).and_return(false)
without_feature(:encoding) { ScratchPad.record :yield }
ScratchPad.recorded.should == :yield
end
end

0 comments on commit 7074b56

Please sign in to comment.