Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 黄瓜罐头';找不到路线?这可能是一个新的大问题_Ruby On Rails_Ruby_Rspec_Ruby On Rails 3_Cucumber - Fatal编程技术网

Ruby on rails 黄瓜罐头';找不到路线?这可能是一个新的大问题

Ruby on rails 黄瓜罐头';找不到路线?这可能是一个新的大问题,ruby-on-rails,ruby,rspec,ruby-on-rails-3,cucumber,Ruby On Rails,Ruby,Rspec,Ruby On Rails 3,Cucumber,带有Rspec2和Cucumber的Rails3应用程序 黄瓜 Given /^that a user is logged in$/ do current_user = User.first render new_user_post_path(current_user) end Routes.rb map.resources :users do |users| users.resources :posts, :collection => {:view => :get}

带有Rspec2和Cucumber的Rails3应用程序

黄瓜

Given /^that a user is logged in$/ do
  current_user = User.first
  render new_user_post_path(current_user)
end
Routes.rb

map.resources :users do |users|
  users.resources :posts, :collection => {:view => :get}
end
发布控制器规范

describe PostsController do
  describe "#new" do
    it "should be successful" do
      get :new
      response.should be_success
    end
  end
end
我的第一次重大史诗性失败

(::) failed steps (::)

No route matches {:controller=>"posts", :action=>"new"} (ActionController::RoutingError)
./features/step_definitions/tasklist_steps.rb:3:in `/^that a user is logged in$/'
features/tasklist.feature:7:in `Given that a user is logged in'

Failing Scenarios:
cucumber features/tasklist.feature:6 # Scenario: List SubmitLink

1 scenario (1 failed)
3 steps (1 failed, 2 skipped)
0m0.147s
rake aborted!

对不起,我太新了。这是我第一次尝试黄瓜(

在Rails3路线中,first-off-map是不推荐的,您可能应该有这样的东西

resources :users do 
    resources :posts
end
按照我通常编写givens的方式,我遵循用户实际使用的路径,在测试数据库中创建用户,然后实际进入登录页面并登录,以便在应用程序中正确设置所有内容

Given /^I have one user "([^\"]*)" with email "([^\"]*)" and password "([^\"]*)"$/ do |username,email, password|
  @user = User.new(:email => email,
                   :username=>username,
                   :password => password,
                   :password_confirmation => password)
   @user.save!
end

Given /^I am an authenticated user$/ do
  name = 'exmample'
  email = 'example@example.com'
  password = 'secret!'

  Given %{I have one user "#{name}" with email "#{email}" and password "#{password}"}
  And %{I go to the user login page}
  And %{I fill in "user_username" with "#{name}"}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Sign in"}
end
我使用它的方式如下:

Feature: 
  In order to reboot my crappy/POS equipment without bothering the awesome Noc Monkeys
  I would like to login to a webpage and see the status of and control the outlets on my equipment

  Background: Valid and authenticated user with at least one outlet to control
    Given I am an authenticated user

  @ok
  Scenario: Viewing All outlets
    Given I am able to control an outlet with index "1"
    And I am on the home page
    Then I should see "server_1"

另外,通常我不会在cucumber步骤中调用render。因为您使用的是模拟浏览器(假设是webrat/capybara),所以您将
访问路径(页面名称)

Rails 3 routes中不推荐使用first-off map,您可能会遇到类似的情况

resources :users do 
    resources :posts
end
按照我通常编写givens的方式,我遵循用户实际使用的路径,在测试数据库中创建用户,然后实际进入登录页面并登录,以便在应用程序中正确设置所有内容

Given /^I have one user "([^\"]*)" with email "([^\"]*)" and password "([^\"]*)"$/ do |username,email, password|
  @user = User.new(:email => email,
                   :username=>username,
                   :password => password,
                   :password_confirmation => password)
   @user.save!
end

Given /^I am an authenticated user$/ do
  name = 'exmample'
  email = 'example@example.com'
  password = 'secret!'

  Given %{I have one user "#{name}" with email "#{email}" and password "#{password}"}
  And %{I go to the user login page}
  And %{I fill in "user_username" with "#{name}"}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Sign in"}
end
我使用它的方式如下:

Feature: 
  In order to reboot my crappy/POS equipment without bothering the awesome Noc Monkeys
  I would like to login to a webpage and see the status of and control the outlets on my equipment

  Background: Valid and authenticated user with at least one outlet to control
    Given I am an authenticated user

  @ok
  Scenario: Viewing All outlets
    Given I am able to control an outlet with index "1"
    And I am on the home page
    Then I should see "server_1"

另外,通常我不会在cucumber步骤中调用render。因为您使用的是模拟浏览器(假设是webrat/capybara),所以您将
访问路径(page\u name)

对。我知道了。谢谢你。我肯定从现在起到成为一个更小的新手,我还会遇到更多的陷阱;)。谢谢你的帮助。我想出来了。非常感谢。我相信从现在起到成为一个更不起眼的新手,我还会遇到更多的陷阱;)。谢谢你的帮助。