Ruby ';获取绑定&x27;“未定义的方法”;id";
这是我使用ERB的代码。 它无法绑定TestCase对象 ERB与对象绑定一起工作吗?TestReport类中有两个方法。如果您对Testcase对象绑定进行注释,代码将按预期工作。如果我试图绑定对象,我会得到以下错误。 “get_binding中的块”:TestCase的“未定义的方法id”Ruby ';获取绑定&x27;“未定义的方法”;id";,ruby,Ruby,这是我使用ERB的代码。 它无法绑定TestCase对象 ERB与对象绑定一起工作吗?TestReport类中有两个方法。如果您对Testcase对象绑定进行注释,代码将按预期工作。如果我试图绑定对象,我会得到以下错误。 “get_binding中的块”:TestCase的“未定义的方法id” #!/usr/bin/ruby require "erb"enter code here # Build template data class. class TestcaseReport d
#!/usr/bin/ruby
require "erb"enter code here
# Build template data class.
class TestcaseReport
def initialize(platform)
@platform = platform
@testcases = [ ]
@features = [ ]
end
def add_testcase(testcase)
@testcases << testcase
end
def add_feature(feature)
@features << feature
end
# Support templating of member data.
def get_binding
binding
end
end
class TestCase
def initialize(id, link, name, testcasetype, time, status )
@id = id
@link = link
@name = name
@testcasetype = testcasetype
@time = time
@status = status
end
end
# Create template.
template = %{
<html>
<head>
<title>BreatheMapper Test Execution Report</title>
<style>
* {
box-sizing: border-box;
}
/* Create columns that floats next to each other */
.column40 {
float: left;
margin: auto;
width: 40%;
}
.column25 {
float: left;
margin: auto;
width: 25%;
}
.column13 {
float: left;
margin: auto;
width: 13%;
}
.column9 {
float: left;
margin: auto;
width: 9%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
div {
border-style: solid;
border-color: #ADD470;
border-width: 1px 1px 0px 1px;
height: auto;
}
</style>
</head>
<body style="color:#4A4A4A;">
<h2 align="center">BretheMapper Android Test Execution Report</h2>
<p><b>Executed By: </b>Manish Rathi<br/>
<b>Build Version Number: </b>0.3.0-alpha-20182006<br/>
<b>Test Execution Date Time: </b>2018-06-26 16:53:17 +0530<br/>
<b>Test Executed on Git Revision: </b><a href="https://scm.sapphirepri.com/Mapper/BreatheMapperIos/tree/9778827">9778827</a></p>
<h5 style="color:#467FBB;">Executed 59 Component tests Your issue occurs because your TestCase
class does not have an id
instance method. To create this method, you can simply add attr_reader :id
to your class.
class TestCase
attr_reader :id
def initialize(id, link, name, testcasetype, time, status )
@id = id
@link = link
@name = name
@testcasetype = testcasetype
@time = time
@status = status
end
end
#/usr/bin/ruby
需要“erb”在此处输入代码
#构建模板数据类。
类TestcaseReport
def初始化(平台)
@站台
@testcases=[]
@功能=[]
结束
def add_测试用例(测试用例)
@testcases您的问题之所以发生,是因为您的TestCase
类没有id
实例方法。要创建此方法,只需向类中添加attr\u reader:id
通过添加此项,当您调用