如何在页面对象类中使用Rspec期望.我需要断言元素.目前我正在使用xpath,其他定位器来检查元素是否存在.我知道使用它是步骤定义.但我需要在课堂上.
class AssertTest
include PageObject
span(:success, text: "Message added successfully")
def assert_element
success_element.when_present (or) success?
# I need to use Rspec expectations instead
# continue...
end
end
Run Code Online (Sandbox Code Playgroud)
在步骤定义中,我可以像以下一样使用它:
@current_page.text.should include "message"
Run Code Online (Sandbox Code Playgroud) 我想使用事件源和 CQRS,所以我需要投影(我希望我使用正确的术语)来更新我的查询数据库。如何处理数据库错误?
例如,我的一个查询缓存数据库不可用,但我已经更新了其他数据库。因此,当它恢复业务时,不可用的数据库将不会与其他数据库处于 snyc 中。它如何知道它必须运行例如来自事件存储的最后 10 个域事件?我想我必须存储有关数据库当前状态的信息,但是如果该数据库状态存储失败怎么办?任何想法,最佳实践如何解决此类问题?
我有一个包含超过 66 个场景的 Cucumber 功能文件!功能文件的标题确实代表了场景的全部内容。
但 66(200 步)感觉是一个相当大的数字。这是否表明我的专题标题过于宽泛?
单个功能文件中的最大场景数是多少(从最佳实践的角度来看)?
提前致谢 :)
我们编写了一些必要的测试,但速度很慢。所以我们配置了 RSpec 来排除它们,除了在 Solano 上,我们设置了一个 ENV 变量。
# spec_helper
unless ENV['RUN_ALL_TESTS'] == 'true'
config.filter_run_excluding :slow
end
Run Code Online (Sandbox Code Playgroud)
这是可行的,但我正在尝试编写一个 rake 任务,我们可以调用它通过设置相同的 ENV 变量然后运行套件来在本地运行每个测试。我在弄清楚如何触发 RSpec 时遇到了麻烦。这就是我现在所拥有的:
# all_tests.rake
require 'rspec/core/rake_task'
desc 'Run all tests, even those usually excluded.'
task all_tests: :environment do
ENV['RUN_ALL_TESTS'] = 'true'
RSpec::Core::RakeTask.new(:spec)
end
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它不运行任何测试。
我发现的大部分内容都是用于在测试中触发 rake 任务、测试 rake 任务或设置 Rakefile。我们正在使用rspec-rails,我们的默认 rake 任务已经设置。
使用Null Object模式时,如果情况无效,您将如何"检查"?例如,当存储库中找不到任何项目时,向用户显示"未找到"消息.
我必须做一个美化的空检查吗?
这些技术似乎打败了Null Object模式本身的目的
我有一些代码是相同的,除了一定的分配顺序发生在略有不同的顺序.
很容易将其分解为类型的方法参数int[],它表示顺序.
但是,我发现它并不是最清楚的.
另一种选择是将它们分解为类型的对象AssignmentOrders.我也可以对对象构造函数中的值进行验证,而这些值是我无法对数组进行的.这将是从书,"引入参数对象"重构重构.
我想知道这种特殊的重构是否过度,我应该坚持下去int[]?
码:
原件的三个样本:
private static PersonDetails parseLine(String line, String deliminator, int[] orderOfSections)
throws Exception {
String[] sections = line.split(deliminator);
String value1 = sections[0].trim();
String value2 = sections[1].trim();
String value3 = sections[4].trim();
String value4 = sections[2].trim();
String value5 = sections[3].trim();
//........
}
private static PersonDetails parseLine(String line, String deliminator)
throws Exception {
String[] sections = line.split(deliminator);
String value1 = sections[1].trim();
String value2 = sections[0].trim();
String value3 = sections[2].trim();
String …Run Code Online (Sandbox Code Playgroud) 有人可以解释使用"Bridge"模式时"Bridge-up"和"Bridge-down"方法之间的区别吗?可能,我只是无法得到这个想法.为了说清楚,我在说什么,请看一下本书的部分内容并加以解释
我决定使用新的Rspec 3(+ capybara/factory_girl)开始一个新项目,并且在学习新语法时遇到了麻烦.现在我有
user_pages_spec.rb(功能)
scenario "Signing Up" do
let(:submit) { "Sign up" }
scenario "With valid information" do
background do
fill_in "Username", with: "bbvoncrumb"
fill_in "Email", with: "bbvoncrumb@example.com"
fill_in "Password", with: "foobar123"
fill_in "Password confirmation", with: "foobar123"
end
scenario "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
Run Code Online (Sandbox Code Playgroud)
使用未定义的方法'let'失败.和:
static_pages_spec.rb(控制器)
describe StaticPagesController do
describe "GET 'home'" do
it "returns http success" do
get :home
expect(response).to be_success
end
end
end
Run Code Online (Sandbox Code Playgroud)
使用"未定义的方法'获取'.(这只是默认的控制器规范)
我正在尝试使用带有State模式的Swing库生成动态画布.我的代码可以编译,但是当按下按钮时,控制台上会出现红色标记.
问题:我的自引用指针或保留字这超出了按钮的范围.我希望能够在没有任何静态的情况下访问该类.
错误:线程"AWT-EventQueue-0"中的异常java.lang.Error:未解决的编译问题:类型State中的方法handlePush(SP)不适用于参数(new ActionListener(){})
这是画布类.
public class SP extends JPanel{
private static final long serialVersionUID = 1L;
private State state = null;
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
createAndShowCanvasGUI();
}
});
}
public SP(State state ){
this.state = state;
init();
}
public SP(){
this(new BlackState());
}
public static void createAndShowCanvasGUI(){
JFrame frm = new JFrame("State Pattern");
frm.setVisible(true);
frm.setSize(400, 400);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setContentPane(new SP());
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(state.getColor());
g.fillRect(0, 0, getWidth(), getHeight());
repaint(); …Run Code Online (Sandbox Code Playgroud) 基本上这个应用程序应该询问你的名字,并有一个保存的选项,当点击时,会弹出一个警告对话框并询问“你确定吗?”,当点击是时,它应该说“欢迎+随便输入什么名字” . 我的问题是该应用程序在说欢迎之前一直关闭。我将字符串声明为 userName 并在没有任何函数的情况下运行它,它只是说“欢迎,空”。但是当我做 userName=editText.getText().toString(); 该应用程序立即关闭。请帮助我的想法。调用欢迎页面的页面工作正常,但welcome.java 是有问题的文件。
public class Welcome extends Activity {
String userName;
final EditText editText=(EditText)findViewById(R.id.editText);
final TextView textView=(TextView)findViewById(R.id.textView);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
final TextView textView=(TextView)findViewById(R.id.textView);
final EditText editText=(EditText)findViewById(R.id.editText);
userName=editText.getText().toString();
textView.setText(String.format("Welcome, %s.", userName));
}
}
Run Code Online (Sandbox Code Playgroud)
logcat 基本上是标题,以下行出错:
userName=editText.getText().toString();
Run Code Online (Sandbox Code Playgroud)
PS我在onCreate之前和之后移动了那行代码,它仍然给出错误
我的 MainActivity.java 是
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.view.View;
public class MainActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); …Run Code Online (Sandbox Code Playgroud)