首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cucumber + Webrat不提交表单?

Cucumber + Webrat不提交表单?
EN

Stack Overflow用户
提问于 2011-02-10 02:18:26
回答 1查看 525关注 0票数 0

我是Cucumber的新手,完全不知道为什么集成测试会失败。我有以下几个场景:

代码语言:javascript
复制
Scenario: User changes profile

    Given I have an account
    When I change my profile
    Then my profile should be saved

Scenario: User changes login

    Given I have an account
    When I change my login information
    Then my account should be changed

这些步骤定义如下:

代码语言:javascript
复制
Given /^I have an account$/ do
    @user = Factory.create(:user)
    visit login_path
    fill_in "Email", :with => @user.email
    fill_in "Password", :with => 'secret'
    click_button "Sign in"
end

When /^I change my profile$/ do
    visit edit_user_profile_path(@user)
    fill_in "First name", :with => "John"
    fill_in "Last name", :with => "Doe"
    click_button "Update Profile"
end

Then /^my profile should be saved$/ do
    @user.profile.first_name.should == "John"
    @user.profile.last_name.should == "Doe"
end

When /^I change my login information$/ do
    visit edit_user_path(@user)
    fill_in "Email", :with => "foo@example.com"
    click_button "Update Login Information"
end

Then /^my account should be changed$/ do
    @user.email.should == "foo@example.com"
end

在这两种情况下,我都不能满足"Then“条件,并显示以下消息:

代码语言:javascript
复制
# Scenario 1
expected: "John"
got: "Test1" (using ==) (RSpec::Expectations::ExpectationNotMetError)

# Scenario 1
expected: "foo@example.com"
got: "test2@example.com" (using ==) (RSpec::Expectations::ExpectationNotMetError)

因此,在这两种情况下,提交表单以更新用户登录或配置文件后,工厂信息仍然存在。但是,如果我在真正的浏览器中测试它,它就能完美地工作。那么,为什么这个测试失败了?

谢谢你的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-10 05:59:45

@user只是一个存在于cucumber代码块中的变量。它将不会被更改。在测试中要更改的是数据库记录。要检查它是否确实已更改,您必须访问显示用户名的某个页面。

(就像你在现实生活中的测试一样)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4948817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档