如何使用黄瓜测试Rack应用程序的创建?

时间:2021-08-23 23:14:58

I am creating a Ruby command line application that will generate a Rack application. I want to test that the Rack application that is created is a valid Rack application. I have started using Aruba and Cucumber to test that the CLI creates the correct files and directory structure, but now I'm ready to run rackup and see that the application is running correctly. How can I get Cucumber and Capybara to interact with this newly created application?

我正在创建一个Ruby命令行应用程序,它将生成一个Rack应用程序。我想测试创建的Rack应用程序是否是有效的Rack应用程序。我已经开始使用Aruba和Cucumber来测试CLI创建正确的文件和目录结构,但现在我已经准备好运行rackup并看到应用程序正在运行。如何让Cucumber和Capybara与这个新创建的应用程序进行交互?

1 个解决方案

#1


0  

Generate a root page for your rack application then have capybara visit whatever path you deem to be your root path and verify some sort of output on that page

为您的机架应用程序生成一个根页,然后让水豚访问您认为是您的根路径的任何路径并验证该页面上的某种输出

def response
   if request.path "/" 
      Rack::Response.new(render("index.html.erb"))  
   else 
      Rack::Response.new("Not Found", 404)
    end
end

on rack startup: @startup_output = "foo" generate some sort of output on your root page <%= @startup_output %>

在机架启动时:@startup_output =“foo”在根页面上生成某种输出<%= @startup_output%>

capybara:

水豚:

visit('/')
page.should have_content('foo')

If you need to have capybara start the app up try using a rake task inside the test:

如果您需要让capybara启动应用程序,请尝试在测试中使用rake任务:

system "rake rack:start"

#1


0  

Generate a root page for your rack application then have capybara visit whatever path you deem to be your root path and verify some sort of output on that page

为您的机架应用程序生成一个根页,然后让水豚访问您认为是您的根路径的任何路径并验证该页面上的某种输出

def response
   if request.path "/" 
      Rack::Response.new(render("index.html.erb"))  
   else 
      Rack::Response.new("Not Found", 404)
    end
end

on rack startup: @startup_output = "foo" generate some sort of output on your root page <%= @startup_output %>

在机架启动时:@startup_output =“foo”在根页面上生成某种输出<%= @startup_output%>

capybara:

水豚:

visit('/')
page.should have_content('foo')

If you need to have capybara start the app up try using a rake task inside the test:

如果您需要让capybara启动应用程序,请尝试在测试中使用rake任务:

system "rake rack:start"