我在使用PHP设置的重定向后遇到Cucumber问题(使用header('Location: xxx')
我已遵循本指南(http://jamieonsoftware.com/journal/2011/1/2/high-level-testing-php-applications-with-cucumber.html)并对我们的网络应用稍作修改。
以下是一个示例场景:
Scenario: Login processing
Given I am on the login page
When I fill in the username input with adam
And I fill in the password input with 798345
And I click the button Login
Then I should see the annoucements
步骤:
Given /I am on the login page/ do
visit "http://domain.com/login.phtml"
end
When /I fill in the (.*) input with (.*)/ do |input, value|
fill_in input, :with => value
end
When /^I click the button (.*)$/ do |button|
click_button button
end
Then /^I should see the annoucements$/ do
response_body.should contain("Announcements")
end
一切都过去了,直到它“我应该看到公告”,然后失败。
我已经浏览了代码,它达到了header('Location: xxx')
,并且它没有遵循标题重定向。
我对Cucumber很新,经过一天的调试后,我想在这里问。
如果有帮助,以下是版本:
[adam ~] cucumber --version
1.2.1
[adam ~] rspec --version
2.12.2
[adam ~] rails -v
Rails 3.2.12
[adam ~] ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.2]
谢谢!
更新
只是为了展示一些行动的代码;
测试场景:
Scenario: Test
Given I am on the test page
When I click the link Test
Then I should see the redirect
测试步骤
Given /I am on the test page/ do
visit "test.php"
end
When /^I click the link (.*)$/ do |button|
click_link button
end
Then /^I should see the redirect$/ do
response_body.should contain("redirect")
end
test.php的
if( isset( $_REQUEST['test'] ) ){
echo 'header';
header( 'Location: test.php?redirect=yes' );
exit;
}
if( isset( $_REQUEST['redirect'] ) ){
echo 'redirect';
exit;
}
echo '<a href="test.php?test=true">Test</a>';
运行此测试时,它会失败;
Then I should see the redirect # _features/step_definitions/tests.rb:10
expected the following element's content to include "redirect":
header (RSpec::Expectations::ExpectationNotMetError)
./_features/step_definitions/tests.rb:11:in `/^I should see the redirect$/'
_features/test.feature:9:in `Then I should see the redirect'
所以它回声'标题',但不遵循header( 'Location: test.php?redirect=yes' );