假设我是猴子修补类中的方法,我怎么能从覆盖方法调用重写方法?就像有点像super
例如
class Foo
def bar()
"Hello"
end
end
class Foo
def bar()
super() + " World"
end
end
>> Foo.new.bar == "Hello World"
Run Code Online (Sandbox Code Playgroud) 来源:JUnit 5、Eclipse 4.8、Selenium
我可以在没有任何特殊测试框架的情况下编写和执行 Selenium 脚本,但我想使用 Junit 5(因为我们依赖其他工具)并且我从未见过这样的错误“org.junit.jupiter.api.extension.ParameterResolutionException”而与 Junit 4 一起工作。目前它是 Junit 5,我用谷歌搜索它以获得某种想法,但无法解决问题。
测试脚本:
package login;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class loginTest {
public WebDriver driver = null ;
public loginTest(WebDriver driver)
{
this.driver=driver;
}
@BeforeEach
public void setUp() throws Exception
{
driver.get("google.com");
System.out.println("Page title is: " + driver.getTitle());
}
@Test
public void test() {
// some action here I have in original script
System.out.println("Page title is: " …Run Code Online (Sandbox Code Playgroud) 我有一个需要与Rails API通信的React客户端应用程序.我想使用rails-ujs方法Rails.ajax.例如:
Rails.ajax({
type: "POST",
url: "/things",
data: mydata,
success: function(response) {...},
error: function(response) {...}
})
Run Code Online (Sandbox Code Playgroud)
看起来我不能data像这样设置JSON对象:
mydata = {
thing: {
field1: value1,
field2: value2,
}}
Run Code Online (Sandbox Code Playgroud)
我需要application/x-www-form-urlencoded手动将其转换为内容类型,如下所示:
mydata = 'thing[field1]=value1&thing[field2]=value2'
Run Code Online (Sandbox Code Playgroud)
这对于平面数据是好的,但对于嵌套数据来说很快就会变得复杂.
jQuery在发出请求之前自动进行转换.
所以我想知道Rails UJS是否有一些自动方式,但我在文档或代码中找不到任何东西.
我有一个类,在一种情况下应该调用:my_method,但在另一种情况下不能调用方法:my_method。我想测试这两种情况。另外,我希望测试记录:my_method不应该被调用的情况。
any_instance通常不鼓励使用,所以我很乐意学习一个很好的方法来替换它。
这段代码片段是我想要编写的测试类型的简化示例。
class TestSubject
def call
call_me
end
def call_me; end
def never_mind; end
end
require 'rspec'
spec = RSpec.describe 'TestSubject' do
describe '#call' do
it 'calls #call_me' do
expect_any_instance_of(TestSubject).to receive(:call_me)
TestSubject.new.call
end
it 'does not call #never_mind' do
expect_any_instance_of(TestSubject).not_to receive(:never_mind)
TestSubject.new.call
end
end
end
spec.run # => true
Run Code Online (Sandbox Code Playgroud)
它有效,但使用了 expect_any_instance_of不推荐的方法。
如何更换?
我想分str成两半并将每一半分配给first和second
像这个伪代码示例:
first,second = str.split( middle )
Run Code Online (Sandbox Code Playgroud)