Ruby on rails 3 我如何在没有测试的情况下使用水豚

Ruby on rails 3 我如何在没有测试的情况下使用水豚,ruby-on-rails-3,capybara,Ruby On Rails 3,Capybara,在数据库中的Rails应用程序中,我有一些查询 # PostController @post.query # => 'blabla' 我想把这个字符串放在谷歌或雅虎 在简单的ruby文件中,我使用 require ... all gems Capybara.app_host = 'http://www.google.com/' 及 但我如何将此代码放入控制器(或模型方法)?水豚不适用于此类用途。您可能想试试。class PostsController@post.query 点击按钮(“

在数据库中的Rails应用程序中,我有一些查询

# PostController
@post.query # => 'blabla'
我想把这个字符串放在谷歌或雅虎

在简单的ruby文件中,我使用

require ... all gems
Capybara.app_host = 'http://www.google.com/'


但我如何将此代码放入控制器(或模型方法)?

水豚不适用于此类用途。您可能想试试。

class PostsController@post.query
点击按钮(“谷歌”)
循环_变量=0
页面的数量=1
页面的最大计数=4
在中断时标记\u=错误
而(loop_variable==0)do
has_on_page=page.has_content?(@post.search_question)
如果在页面上有
循环_变量=1
其他的
查找('.b:最后一个a')。单击
页面的数量+=1
结束
如果页面的数量>页面的最大数量
在中断时标记=真
打破
结束
结束
如果旗子坏了
@数字='未找到任何内容'
其他的
@数字=第页的数字
结束
结束
def新
@post=post.new
结束
def创建
@post=post.new(参数[:post])
如果@post.save
flash[:注意]=“已创建帖子!”
将\重定向到根\路径
结束
结束
结束

这是我的一段代码,但我认为主要的想法是可以理解的

我发现如何将google search与capybara结合使用(当我有时间时,我会给出答案)
class Google
  include Capybara::DSL
  def search
    visit('/')
    fill_in "q", :with => "blah blah" 
    click_button("Google")
    ...
class PostsController < ApplicationController

require 'capybara'
require 'capybara/dsl'

include Capybara::DSL

Capybara.current_driver = :webkit

  def index
    @posts = Post.all
  end

  def show
    @post = Post.find(params[:id])
     visit(@post.search_type)
     fill_in "q", :with => @post.query 
     click_button("Google")

     loop_variable = 0
     num_of_page = 1
     max_count_of_page = 4
     flag_on_break = false

     while(loop_variable == 0) do
       has_on_page = page.has_content?(@post.search_question)

       if has_on_page
         loop_variable = 1
       else
         find('.b:last a').click
         num_of_page += 1
       end
         if num_of_page > max_count_of_page
           flag_on_break = true
           break
           end
         end

      if flag_on_break
        @number = 'Nothing not found'
      else
        @number = num_of_page
      end  
  end

  def new
    @post = Post.new
  end

  def create
    @post = Post.new(params[:post])

    if @post.save
      flash[:notice] = "Post created!"
      redirect_to root_path
    end
  end
end