Merge pull request #2024 from reitermarkus/spec-build_environment

Convert BuildEnvironment test to spec.
This commit is contained in:
Markus Reiter 2017-02-16 01:01:57 +01:00 committed by GitHub
commit 01f90b0d33
2 changed files with 66 additions and 46 deletions

View File

@ -0,0 +1,66 @@
require "build_environment"
RSpec::Matchers.alias_matcher :use_userpaths, :be_userpaths
describe BuildEnvironment do
let(:env) { described_class.new }
describe "#<<" do
it "returns itself" do
expect(env << :foo).to be env
end
end
describe "#merge" do
it "returns itself" do
expect(env.merge([])).to be env
end
end
describe "#std?" do
it "returns true if the environment contains :std" do
env << :std
expect(env).to be_std
end
it "returns false if the environment does not contain :std" do
expect(env).not_to be_std
end
end
describe "#userpaths?" do
it "returns true if the environment contains :userpaths" do
env << :userpaths
expect(env).to use_userpaths
end
it "returns false if the environment does not contain :userpaths" do
expect(env).not_to use_userpaths
end
end
end
describe BuildEnvironmentDSL do
subject { double.extend(described_class) }
context "single argument" do
before(:each) do
subject.instance_eval do
env :userpaths
end
end
its(:env) { is_expected.to use_userpaths }
end
context "multiple arguments" do
before(:each) do
subject.instance_eval do
env :userpaths, :std
end
end
its(:env) { is_expected.to be_std }
its(:env) { is_expected.to use_userpaths }
end
end

View File

@ -1,46 +0,0 @@
require "testing_env"
require "build_environment"
class BuildEnvironmentTests < Homebrew::TestCase
def setup
super
@env = BuildEnvironment.new
end
def test_shovel_returns_self
assert_same @env, @env << :foo
end
def test_merge_returns_self
assert_same @env, @env.merge([])
end
def test_std?
@env << :std
assert_predicate @env, :std?
end
def test_userpaths?
@env << :userpaths
assert_predicate @env, :userpaths?
end
end
class BuildEnvironmentDSLTests < Homebrew::TestCase
def make_instance(&block)
obj = Object.new.extend(BuildEnvironmentDSL)
obj.instance_eval(&block)
obj
end
def test_env_single_argument
obj = make_instance { env :userpaths }
assert_predicate obj.env, :userpaths?
end
def test_env_multiple_arguments
obj = make_instance { env :userpaths, :std }
assert_predicate obj.env, :userpaths?
assert_predicate obj.env, :std?
end
end