complete spec updates for RSpec 3 using only :expect syntax
This commit is contained in:
parent
5783ed993a
commit
31968e7e32
@ -37,16 +37,15 @@ describe Rscons do
|
|||||||
end
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@output = ""
|
@saved_stdout = $stdout
|
||||||
$stdout.stub(:write) do |content|
|
$stdout = StringIO.new
|
||||||
@output += content
|
@saved_stderr = $stderr
|
||||||
end
|
$stderr = StringIO.new
|
||||||
$stderr.stub(:write) do |content|
|
|
||||||
@output += content
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
|
$stdout = @saved_stdout
|
||||||
|
$stderr = @saved_stderr
|
||||||
Dir.chdir(@owd)
|
Dir.chdir(@owd)
|
||||||
rm_rf(BUILD_TEST_RUN_DIR)
|
rm_rf(BUILD_TEST_RUN_DIR)
|
||||||
end
|
end
|
||||||
@ -68,9 +67,10 @@ describe Rscons do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def lines
|
def lines
|
||||||
@output.lines.map(&:rstrip).tap do |v|
|
rv = ($stdout.string + $stderr.string).lines.map(&:rstrip)
|
||||||
@output = ""
|
$stdout.string = ""
|
||||||
end
|
$stderr.string = ""
|
||||||
|
rv
|
||||||
end
|
end
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
@ -6,9 +6,9 @@ module Rscons
|
|||||||
|
|
||||||
it "supports overriding DISASM_CMD construction variable" do
|
it "supports overriding DISASM_CMD construction variable" do
|
||||||
cache = "cache"
|
cache = "cache"
|
||||||
cache.stub(:up_to_date?) { false }
|
allow(cache).to receive(:up_to_date?) { false }
|
||||||
cache.stub(:mkdir_p) { }
|
allow(cache).to receive(:mkdir_p) { }
|
||||||
cache.stub(:register_build) { }
|
allow(cache).to receive(:register_build) { }
|
||||||
expect(env).to receive(:execute).with("Disassemble a_file.txt", ["my_disasm", "a_file.exe"], anything).and_return(true)
|
expect(env).to receive(:execute).with("Disassemble a_file.txt", ["my_disasm", "a_file.exe"], anything).and_return(true)
|
||||||
subject.run("a_file.txt", ["a_file.exe"], cache, env, "DISASM_CMD" => ["my_disasm", "${_SOURCES}"])
|
subject.run("a_file.txt", ["a_file.exe"], cache, env, "DISASM_CMD" => ["my_disasm", "${_SOURCES}"])
|
||||||
end
|
end
|
||||||
|
@ -6,11 +6,11 @@ module Rscons
|
|||||||
|
|
||||||
it "supports overriding CCCMD construction variable" do
|
it "supports overriding CCCMD construction variable" do
|
||||||
cache = "cache"
|
cache = "cache"
|
||||||
cache.stub(:up_to_date?) { false }
|
allow(cache).to receive(:up_to_date?) { false }
|
||||||
cache.stub(:mkdir_p) { }
|
allow(cache).to receive(:mkdir_p) { }
|
||||||
cache.stub(:register_build) { }
|
allow(cache).to receive(:register_build) { }
|
||||||
FileUtils.stub(:rm_f) { }
|
allow(FileUtils).to receive(:rm_f) { }
|
||||||
File.stub(:exists?) { false }
|
allow(File).to receive(:exists?) { false }
|
||||||
expect(env).to receive(:execute).with("CC mod.o", ["llc", "mod.c"]).and_return(true)
|
expect(env).to receive(:execute).with("CC mod.o", ["llc", "mod.c"]).and_return(true)
|
||||||
subject.run("mod.o", ["mod.c"], cache, env, "CCCMD" => ["llc", "${_SOURCES}"])
|
subject.run("mod.o", ["mod.c"], cache, env, "CCCMD" => ["llc", "${_SOURCES}"])
|
||||||
end
|
end
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
describe Cache do
|
describe Cache do
|
||||||
before do
|
before do
|
||||||
File.stub(:read) { nil }
|
allow(File).to receive(:read) { nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_from(cache)
|
def build_from(cache)
|
||||||
JSON.stub(:load) do
|
allow(JSON).to receive(:load) do
|
||||||
cache
|
cache
|
||||||
end
|
end
|
||||||
Cache.instance.tap do |cache|
|
Cache.instance.tap do |cache|
|
||||||
@ -28,7 +28,7 @@ module Rscons
|
|||||||
describe "#clear" do
|
describe "#clear" do
|
||||||
it "removes the cache file" do
|
it "removes the cache file" do
|
||||||
expect(FileUtils).to receive(:rm_f).with(Cache::CACHE_FILE)
|
expect(FileUtils).to receive(:rm_f).with(Cache::CACHE_FILE)
|
||||||
JSON.stub(:load) {{}}
|
allow(JSON).to receive(:load) {{}}
|
||||||
Cache.instance.clear
|
Cache.instance.clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -47,7 +47,7 @@ module Rscons
|
|||||||
describe "#up_to_date?" do
|
describe "#up_to_date?" do
|
||||||
empty_env = "env"
|
empty_env = "env"
|
||||||
before do
|
before do
|
||||||
empty_env.stub(:get_user_deps) { nil }
|
allow(empty_env).to receive(:get_user_deps) { nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when target file does not exist" do
|
it "returns false when target file does not exist" do
|
||||||
|
@ -205,7 +205,7 @@ module Rscons
|
|||||||
cache = "cache"
|
cache = "cache"
|
||||||
expect(Cache).to receive(:instance).and_return(cache)
|
expect(Cache).to receive(:instance).and_return(cache)
|
||||||
expect(cache).to receive(:clear_checksum_cache!)
|
expect(cache).to receive(:clear_checksum_cache!)
|
||||||
env.stub(:run_builder) do |builder, target, sources, cache, vars|
|
allow(env).to receive(:run_builder) do |builder, target, sources, cache, vars|
|
||||||
raise "Ruby exception thrown by builder"
|
raise "Ruby exception thrown by builder"
|
||||||
end
|
end
|
||||||
expect(cache).to receive(:write)
|
expect(cache).to receive(:write)
|
||||||
@ -349,11 +349,11 @@ module Rscons
|
|||||||
build_op[:vars]["CFLAGS"] += ["-O3", "-DSPECIAL"]
|
build_op[:vars]["CFLAGS"] += ["-O3", "-DSPECIAL"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
env.builders["Object"].stub(:run) do |target, sources, cache, env, vars|
|
allow(env.builders["Object"]).to receive(:run) do |target, sources, cache, env, vars|
|
||||||
expect(vars["CFLAGS"]).to eq []
|
expect(vars["CFLAGS"]).to eq []
|
||||||
end
|
end
|
||||||
env.run_builder(env.builders["Object"], "build/normal/module.o", ["src/normal/module.c"], "cache", {})
|
env.run_builder(env.builders["Object"], "build/normal/module.o", ["src/normal/module.c"], "cache", {})
|
||||||
env.builders["Object"].stub(:run) do |target, sources, cache, env, vars|
|
allow(env.builders["Object"]).to receive(:run) do |target, sources, cache, env, vars|
|
||||||
expect(vars["CFLAGS"]).to eq ["-O3", "-DSPECIAL"]
|
expect(vars["CFLAGS"]).to eq ["-O3", "-DSPECIAL"]
|
||||||
end
|
end
|
||||||
env.run_builder(env.builders["Object"], "build/special/module.o", ["src/special/module.c"], "cache", {})
|
env.run_builder(env.builders["Object"], "build/special/module.o", ["src/special/module.c"], "cache", {})
|
||||||
|
@ -2,23 +2,23 @@ describe Rscons do
|
|||||||
describe ".clean" do
|
describe ".clean" do
|
||||||
it "removes all build targets and created directories" do
|
it "removes all build targets and created directories" do
|
||||||
cache = "cache"
|
cache = "cache"
|
||||||
Rscons::Cache.should_receive(:instance).and_return(cache)
|
expect(Rscons::Cache).to receive(:instance).and_return(cache)
|
||||||
cache.should_receive(:targets).and_return(["build/a.out", "build/main.o"])
|
expect(cache).to receive(:targets).and_return(["build/a.out", "build/main.o"])
|
||||||
FileUtils.should_receive(:rm_f).with("build/a.out")
|
expect(FileUtils).to receive(:rm_f).with("build/a.out")
|
||||||
FileUtils.should_receive(:rm_f).with("build/main.o")
|
expect(FileUtils).to receive(:rm_f).with("build/main.o")
|
||||||
cache.should_receive(:directories).and_return(["build/one", "build/one/two", "build", "other"])
|
expect(cache).to receive(:directories).and_return(["build/one", "build/one/two", "build", "other"])
|
||||||
File.should_receive(:directory?).with("build/one/two").and_return(true)
|
expect(File).to receive(:directory?).with("build/one/two").and_return(true)
|
||||||
Dir.should_receive(:entries).with("build/one/two").and_return([".", ".."])
|
expect(Dir).to receive(:entries).with("build/one/two").and_return([".", ".."])
|
||||||
Dir.should_receive(:rmdir).with("build/one/two")
|
expect(Dir).to receive(:rmdir).with("build/one/two")
|
||||||
File.should_receive(:directory?).with("build/one").and_return(true)
|
expect(File).to receive(:directory?).with("build/one").and_return(true)
|
||||||
Dir.should_receive(:entries).with("build/one").and_return([".", ".."])
|
expect(Dir).to receive(:entries).with("build/one").and_return([".", ".."])
|
||||||
Dir.should_receive(:rmdir).with("build/one")
|
expect(Dir).to receive(:rmdir).with("build/one")
|
||||||
File.should_receive(:directory?).with("build").and_return(true)
|
expect(File).to receive(:directory?).with("build").and_return(true)
|
||||||
Dir.should_receive(:entries).with("build").and_return([".", ".."])
|
expect(Dir).to receive(:entries).with("build").and_return([".", ".."])
|
||||||
Dir.should_receive(:rmdir).with("build")
|
expect(Dir).to receive(:rmdir).with("build")
|
||||||
File.should_receive(:directory?).with("other").and_return(true)
|
expect(File).to receive(:directory?).with("other").and_return(true)
|
||||||
Dir.should_receive(:entries).with("other").and_return([".", "..", "other.file"])
|
expect(Dir).to receive(:entries).with("other").and_return([".", "..", "other.file"])
|
||||||
cache.should_receive(:clear)
|
expect(cache).to receive(:clear)
|
||||||
|
|
||||||
Rscons.clean
|
Rscons.clean
|
||||||
end
|
end
|
||||||
@ -35,34 +35,34 @@ describe Rscons do
|
|||||||
|
|
||||||
it "uses the SHELL environment variable if it tests successfully" do
|
it "uses the SHELL environment variable if it tests successfully" do
|
||||||
my_ENV = {"SHELL" => "my_shell"}
|
my_ENV = {"SHELL" => "my_shell"}
|
||||||
ENV.stub(:[]) {|*args| my_ENV[*args]}
|
allow(ENV).to receive(:[]) {|*args| my_ENV[*args]}
|
||||||
io = StringIO.new("success\n")
|
io = StringIO.new("success\n")
|
||||||
IO.should_receive(:popen).with(["my_shell", "-c", "echo success"]).and_yield(io)
|
expect(IO).to receive(:popen).with(["my_shell", "-c", "echo success"]).and_yield(io)
|
||||||
expect(Rscons.get_system_shell).to eq(["my_shell", "-c"])
|
expect(Rscons.get_system_shell).to eq(["my_shell", "-c"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses sh -c on a mingw platform if it tests successfully" do
|
it "uses sh -c on a mingw platform if it tests successfully" do
|
||||||
my_ENV = {"SHELL" => nil}
|
my_ENV = {"SHELL" => nil}
|
||||||
ENV.stub(:[]) {|*args| my_ENV[*args]}
|
allow(ENV).to receive(:[]) {|*args| my_ENV[*args]}
|
||||||
io = StringIO.new("success\n")
|
io = StringIO.new("success\n")
|
||||||
IO.should_receive(:popen).with(["sh", "-c", "echo success"]).and_yield(io)
|
expect(IO).to receive(:popen).with(["sh", "-c", "echo success"]).and_yield(io)
|
||||||
Object.should_receive(:const_get).with("RUBY_PLATFORM").and_return("x86-mingw")
|
expect(Object).to receive(:const_get).with("RUBY_PLATFORM").and_return("x86-mingw")
|
||||||
expect(Rscons.get_system_shell).to eq(["sh", "-c"])
|
expect(Rscons.get_system_shell).to eq(["sh", "-c"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses cmd /c on a mingw platform if sh -c does not test successfully" do
|
it "uses cmd /c on a mingw platform if sh -c does not test successfully" do
|
||||||
my_ENV = {"SHELL" => nil}
|
my_ENV = {"SHELL" => nil}
|
||||||
ENV.stub(:[]) {|*args| my_ENV[*args]}
|
allow(ENV).to receive(:[]) {|*args| my_ENV[*args]}
|
||||||
io = StringIO.new("success\n")
|
io = StringIO.new("success\n")
|
||||||
IO.should_receive(:popen).with(["sh", "-c", "echo success"]).and_raise "ENOENT"
|
expect(IO).to receive(:popen).with(["sh", "-c", "echo success"]).and_raise "ENOENT"
|
||||||
Object.should_receive(:const_get).with("RUBY_PLATFORM").and_return("x86-mingw")
|
expect(Object).to receive(:const_get).with("RUBY_PLATFORM").and_return("x86-mingw")
|
||||||
expect(Rscons.get_system_shell).to eq(["cmd", "/c"])
|
expect(Rscons.get_system_shell).to eq(["cmd", "/c"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "uses sh -c on a non-mingw platform if SHELL is not specified" do
|
it "uses sh -c on a non-mingw platform if SHELL is not specified" do
|
||||||
my_ENV = {"SHELL" => nil}
|
my_ENV = {"SHELL" => nil}
|
||||||
ENV.stub(:[]) {|*args| my_ENV[*args]}
|
allow(ENV).to receive(:[]) {|*args| my_ENV[*args]}
|
||||||
Object.should_receive(:const_get).with("RUBY_PLATFORM").and_return("x86-linux")
|
expect(Object).to receive(:const_get).with("RUBY_PLATFORM").and_return("x86-linux")
|
||||||
expect(Rscons.get_system_shell).to eq(["sh", "-c"])
|
expect(Rscons.get_system_shell).to eq(["sh", "-c"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -78,28 +78,28 @@ describe Rscons do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns ['env'] if mingw platform in MSYS and 'env' works" do
|
it "returns ['env'] if mingw platform in MSYS and 'env' works" do
|
||||||
Object.should_receive(:const_get).and_return("x86-mingw")
|
expect(Object).to receive(:const_get).and_return("x86-mingw")
|
||||||
ENV.should_receive(:keys).and_return(["MSYSCON"])
|
expect(ENV).to receive(:keys).and_return(["MSYSCON"])
|
||||||
io = StringIO.new("success\n")
|
io = StringIO.new("success\n")
|
||||||
IO.should_receive(:popen).with(["env", "echo", "success"]).and_yield(io)
|
expect(IO).to receive(:popen).with(["env", "echo", "success"]).and_yield(io)
|
||||||
expect(Rscons.command_executer).to eq(["env"])
|
expect(Rscons.command_executer).to eq(["env"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns [] if mingw platform in MSYS and 'env' does not work" do
|
it "returns [] if mingw platform in MSYS and 'env' does not work" do
|
||||||
Object.should_receive(:const_get).and_return("x86-mingw")
|
expect(Object).to receive(:const_get).and_return("x86-mingw")
|
||||||
ENV.should_receive(:keys).and_return(["MSYSCON"])
|
expect(ENV).to receive(:keys).and_return(["MSYSCON"])
|
||||||
IO.should_receive(:popen).with(["env", "echo", "success"]).and_raise "ENOENT"
|
expect(IO).to receive(:popen).with(["env", "echo", "success"]).and_raise "ENOENT"
|
||||||
expect(Rscons.command_executer).to eq([])
|
expect(Rscons.command_executer).to eq([])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns [] if mingw platform not in MSYS" do
|
it "returns [] if mingw platform not in MSYS" do
|
||||||
Object.should_receive(:const_get).and_return("x86-mingw")
|
expect(Object).to receive(:const_get).and_return("x86-mingw")
|
||||||
ENV.should_receive(:keys).and_return(["COMSPEC"])
|
expect(ENV).to receive(:keys).and_return(["COMSPEC"])
|
||||||
expect(Rscons.command_executer).to eq([])
|
expect(Rscons.command_executer).to eq([])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns [] if not mingw platform" do
|
it "returns [] if not mingw platform" do
|
||||||
Object.should_receive(:const_get).and_return("x86-linux")
|
expect(Object).to receive(:const_get).and_return("x86-linux")
|
||||||
expect(Rscons.command_executer).to eq([])
|
expect(Rscons.command_executer).to eq([])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user