Ruby Puts语句未将消息打印到控制台
我在脚本中放置了一些Ruby Puts语句未将消息打印到控制台,ruby,rspec,pageobjects,Ruby,Rspec,Pageobjects,我在脚本中放置了一些put语句。但是这些信息没有打印出来;脚本正在传递这些语句。我观察到执行进入rakeput的时刻在整个流程中都不起作用 规范内辅助对象 class Testbed puts "Inside test bed" // This puts is printed some code some code some code some code end RSpec.configure do |config| puts "In side rspec config" // This
put
语句。但是这些信息没有打印出来;脚本正在传递这些语句。我观察到执行进入rakeput
的时刻在整个流程中都不起作用
规范内辅助对象
class Testbed
puts "Inside test bed" // This puts is printed
some code
some code
some code
some code
end
RSpec.configure do |config|
puts "In side rspec config" // This puts is printed
config.color = true
config.tty = true
some code
some code
some code
some code
end
config.before(:all) do
puts "in before all"//not printed
这里的put
语句都没有打印输出。My将
放入页面对象中,不考虑等级库文件
有谁能提出解决办法吗?考虑一下默认情况下
将输出放在哪里。除非你告诉它,例如:
File.open('foo', 'w') do |fo|
fo.puts 'bar'
end
当它使用$stdout
或stdout
时,调用程序,尤其是在子shell中使用Ruby的程序,可以捕获输出并对其执行所需操作。这是操作系统的一个特点。如果我将此代码保存在“test.rb”中:
puts 'foo'
从外壳上称之为:
ruby /path/to/test.rb > /some/file.txt
输出将通过管道传输到/some/file.txt,我在控制台上看不到它。类似地,如果我有第二个应用程序调用第一个:
output = %x[ruby /path/to/test.rb]
变量output
将包含文本'foo'
,该文本是从正在重新路由的子shell标准输出中捕获的
有很多方法可以做到这一点,从使用反勾号或%x[…]
到在常规的open
命令中使用或管道,再到Open3中的方法。在打开文件时讨论文件名,例如:
以“|”开头的字符串表示子流程。“|”后面的字符串的其余部分将作为一个进程调用,并连接相应的输入/输出通道
因此,问我们为什么put
没有输出到您的控制台并不容易回答,但您可以看到,如果有什么东西直接调用Ruby之外的代码,那么这很容易做到。考虑一下默认情况下在哪里放置输出。除非你告诉它,例如:
File.open('foo', 'w') do |fo|
fo.puts 'bar'
end
当它使用$stdout
或stdout
时,调用程序,尤其是在子shell中使用Ruby的程序,可以捕获输出并对其执行所需操作。这是操作系统的一个特点。如果我将此代码保存在“test.rb”中:
puts 'foo'
从外壳上称之为:
ruby /path/to/test.rb > /some/file.txt
输出将通过管道传输到/some/file.txt,我在控制台上看不到它。类似地,如果我有第二个应用程序调用第一个:
output = %x[ruby /path/to/test.rb]
变量output
将包含文本'foo'
,该文本是从正在重新路由的子shell标准输出中捕获的
有很多方法可以做到这一点,从使用反勾号或%x[…]
到在常规的open
命令中使用或管道,再到Open3中的方法。在打开文件时讨论文件名,例如:
以“|”开头的字符串表示子流程。“|”后面的字符串的其余部分将作为一个进程调用,并连接相应的输入/输出通道
因此,问我们为什么put
没有输出到您的控制台并不容易,但您可以看到,如果有什么东西直接调用Ruby之外的代码,这很容易做到
有谁能建议解决这个问题的方法吗
首先,注意你所有的错误怎么样
`<main>': undefined method `config' for RSpec:Module (NoMethodError)
…并且配置变量仅在块内定义。然后你写下:
config.before(:all) do
puts "in before all"//not printed
end
该代码不在块内,因此config变量不存在
接下来,before()只在其他测试之前执行——但是您没有测试,正如rspec输出所示:
$ rspec 1.rb
Inside test bed
In side rspec config
No examples found. #*********HERE
Finished in 0.00032 seconds (files took 0.0879 seconds to load)
0 examples, 0 failures #*******HERE
试试这个:
class Testbed
puts "Inside test bed" #This puts is printed
end
RSpec.configure do |config|
puts "In side rspec config" #This puts is printed
config.color = true
config.tty = true
config.before(:all) do
puts "in before all" #?????
end
end
#Here is an rspec test:
RSpec.describe do
it "some test" do
end
end
有谁能建议解决这个问题的方法吗
首先,注意你所有的错误怎么样
`<main>': undefined method `config' for RSpec:Module (NoMethodError)
…并且配置变量仅在块内定义。然后你写下:
config.before(:all) do
puts "in before all"//not printed
end
该代码不在块内,因此config变量不存在
接下来,before()只在其他测试之前执行——但是您没有测试,正如rspec输出所示:
$ rspec 1.rb
Inside test bed
In side rspec config
No examples found. #*********HERE
Finished in 0.00032 seconds (files took 0.0879 seconds to load)
0 examples, 0 failures #*******HERE
试试这个:
class Testbed
puts "Inside test bed" #This puts is printed
end
RSpec.configure do |config|
puts "In side rspec config" #This puts is printed
config.color = true
config.tty = true
config.before(:all) do
puts "in before all" #?????
end
end
#Here is an rspec test:
RSpec.describe do
it "some test" do
end
end
你有任何规格吗?我想你需要发布一个最低限度的工作示例,以便人们可以复制它,你如何调用你的放置的未打印的代码?你有任何规格吗?我想你需要发布一个最低限度的工作示例,以便人们可以复制它,如果您的put
未被打印,您如何调用代码?如何打印变量branchName=options[:name]放置(消息:“创建名为:”)的新分支
。我想打印此语句中的branchName变量。如何打印变量branchName=options[:name]放置(消息:“创建名为:”)的新分支
。我想打印此语句中的branchName变量。