我想知道如何简单地允许所有异常在请求规范中间冒泡到 rspec。
我希望有一个例子可以说明这一点。假设我有以下请求规范和相应的应用程序代码:
# user_browses_posts_spec.rb
feature 'User views a post' do
scenario 'this should fail with route missing' do
FactoryGirl.create(:post)
visit(root_path)
click_on('View Post')
end
end
# config/routes.rb
MyApp::Application.routes.draw do
root to: 'posts#index'
# notice I have not defined a :posts resource, so post_path should raise NoMethodError
end
# assume a totally standard app/controllers/posts_controller.rb
# app/views/posts/index.html.erb
<% @posts.each do |post| %>
<%= link_to 'View Post', post_path(post) %> # this line should fail
<% end %>
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,我看到的是:
Failure/Error: click_on('View Post')
Capybara::ElementNotFound:
no …Run Code Online (Sandbox Code Playgroud) 我在〜/ Library/LaunchAgents中有以下plist文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.yogapo.test_launchd</string>
<key>Program</key>
<string>. /Users/luke/dev/data_yogapo/script/test_launchd.sh</string>
<key>StartInterval</key>
<integer>10</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
test_launchd.sh文件包含以下内容:
#! /bin/bash
echo "hello world from test_launchd.sh" >> /Users/luke/dev/data_yogapo/log/development.log
Run Code Online (Sandbox Code Playgroud)
当我手动运行test_launchd.sh时
. /Users/luke/dev/data_yogapo/script/test_launchd.sh
,结果与预期一致:该行出现在结尾处development.log
但是当我加载这个plist文件时,没有任何反应:
$ cd ~/Library/LaunchAgents
$ launchctl load com.yogapo.test_launchd.plist
$ launchctl list | grep yogapo
- 1 com.yogapo.test_launchd
Run Code Online (Sandbox Code Playgroud)
我已经尝试过使用和不使用RunAtLoad键.我在这里以及互联网上的其他地方看过其他答案.我已经按照教程,并没有发生任何事情.任何帮助非常感谢 - 谢谢!