gpt4 book ai didi

ruby - "it"关键字在 RSpec 中有什么作用?

转载 作者:数据小太阳 更新时间:2023-10-29 06:35:13 25 4
gpt4 key购买 nike

我正在学习 rails3tutorial,但在进行如下测试时,我不明白“it”关键字的含义:

require 'spec_helper'

describe UsersController do
render_views

describe "GET 'new'" do
it "should be successful" do
get 'new'
response.should be_success
end

it "should have the right title" do
get 'new'
response.should have_selector("title", :content => "Sign up")
end
end
end

代码片段来自:http://ruby.railstutorial.org/chapters/filling-in-the-layout#top list 5.26

最佳答案

我认为其他答案可能会更明确,并且最初可能让您感到困惑的是 it 打破了大多数常用的方法命名约定(关于方法的任何内容都没有描述它的内容做,例如)为了使代码作为一个整体被阅读为一种句子。

因此,该库不只是创建一组测试,而是试图鼓励您以类似于人类可读规范的方式通过测试描述您的应用程序。

关于ruby - "it"关键字在 RSpec 中有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8883434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com