与RSpec和Capybara合作,我得到了一个有趣的测试失败模式,它在测试用例中有一些细微的线条重排......这些都不重要.
我正在开发自己的身份验证系统.它目前正在工作,我可以使用浏览器和会话工作等登录/退出.但是,尝试测试这是失败的.正在发生的事情我不太明白,这似乎取决于(看似)不相关的电话的顺序.
require 'spec_helper'
describe "Sessions" do
it 'allows user to login' do
#line one
user = Factory(:user)
#For SO, this method hashes the input password and saves the record
user.password! '2468'
#line two
visit '/sessions/index'
fill_in 'Email', :with => user.email
fill_in 'Password', :with => '2468'
click_button 'Sign in'
page.should have_content('Logged in')
end
end
Run Code Online (Sandbox Code Playgroud)
原样,该测试失败......登录失败.在将'调试器'调用插入规范和控制器后,我可以看到原因:就控制器而言,用户没有插入数据库:
编辑在ApplicationController中添加
class ApplicationController < ActionController::Base
helper :all
protect_from_forgery
helper_method :user_signed_in?, :guest_user?, :current_user
def user_signed_in?
!(session[:user_id].nil? || current_user.new_record?)
end
def guest_user?
current_user.new_record?
end
def current_user …Run Code Online (Sandbox Code Playgroud) 我正在编写一些带有文件的代码,将该文件传递给多个二进制文件之一进行处理,并监视转换过程中的错误.我已经在OSX上编写并测试了以下例程,但linux因为我不清楚的原因而失败了.
#run the command, capture the output so it doesn't display
PTY.spawn(command) {|r,w,pid|
until r.eof? do
##mark
puts r.readline
end
}
Run Code Online (Sandbox Code Playgroud)
运行的命令变化很大,##标记处的代码已简化为本地回显以尝试调试问题.该命令执行,脚本在终端中打印预期的输出,然后抛出异常.
它在Debian系统上产生的错误是: Errno::EIO (Input/output error - /dev/pts/0):
我可以提出的所有命令字符串都会产生错误,当我运行没有本地echo块的代码时,它运行得很好:
PTY.spawn(command) {|r,w,pid|}
Run Code Online (Sandbox Code Playgroud)
在任何一种情况下,命令本身执行正常,但似乎debian linux没有发送eof up the pty.PTY文档页面和ruby-doc上的IO似乎没有任何帮助.
有什么建议?谢谢.
-vox-
我的智慧结束了.我在OSX10.6上,我的宝石都搞砸了.我试图使用的宝石之一是Hashie.我在互联网上环顾四周,有几个人似乎遇到了类似的问题,但我的解决方案似乎都不适用于我的情况.谢谢你的期待.
我的所有ruby脚本/ gem都安装在/opt/ruby-enterprise-1.8.7-2010.02中:
Komputor:~$ which ruby gem irb rails
/opt/ruby-enterprise-1.8.7-2010.02/bin/ruby
/opt/ruby-enterprise-1.8.7-2010.02/bin/gem
/opt/ruby-enterprise-1.8.7-2010.02/bin/irb
/opt/ruby-enterprise-1.8.7-2010.02/bin/rails
Run Code Online (Sandbox Code Playgroud)
并安装了示例gem,hashie(和许多其他):
Komputor:~ $ gem list -l | wc -l
67
Komputor:~ $ gem list | grep hashie
hashie (0.4.0)
Komputor:gems $ cd /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems
Komputor:gems $ ls | grep hashie
drwxr-xr-x 13 root admin 442 Nov 24 17:13 hashie-0.4.0
Run Code Online (Sandbox Code Playgroud)
然而,当我尝试从irb或脚本访问它们时,它都失败了:
Komputor:~ $ irb
irb(main):001:0> require 'hashie'
LoadError: no such file to load -- hashie
from (irb):1:in `require'
from (irb):1
irb(main):002:0>
Run Code Online (Sandbox Code Playgroud)
一些环境变量:Gem env:
Komputor:gems $ gem env
RubyGems Environment: …Run Code Online (Sandbox Code Playgroud) 刚发现琥珀......看起来很棒!如何在Ubuntu服务器上部署示例应用程序?应该像Rails一样完成,将路径路由到public?或者结构的其他部分?
谢谢你的建议.
我的代码是Arduinoish.我打开了详细编译,因此我可以验证所有.o文件确实正确地传递给链接器,它们是(下面的链接器命令).这让我相信它是某种语法错误.
谷歌搜索错误"未定义的函数引用"产生了很多结果,如"将foo.o添加到您的链接器命令"等答案,等等.
我希望解决方案就像丢失点或 - >某处一样简单.
我在链接器中的一个文件中收到了这一系列错误:
SerialServoControl.cpp.o: In function `SerialServoControl::send(int, int)':
SerialServoControl.cpp:31: undefined reference to `SerialServoControl::_serial'
SerialServoControl.cpp:31: undefined reference to `SerialServoControl::_serial'
SerialServoControl.cpp.o: In function `SerialServoControl::init(char, char)':
SerialServoControl.cpp:9: undefined reference to `SerialServoControl::_tx'
SerialServoControl.cpp:10: undefined reference to `SerialServoControl::_rx'
Run Code Online (Sandbox Code Playgroud)
.h文件:
#ifndef SERIALSERVOCONTROL_H
#define SERIALSERVOCONTROL_H
#include "NewSoftSerial.h"
class SerialServoControl {
public:
// rx, tx
static NewSoftSerial _serial;//(9, 8);
int _servo_id;
static char _tx;
static char _rx;
static void init(char tx, char rx);
static void send(int servo_id, int angle);
void setup(int servo_id);
void set(int spot); …Run Code Online (Sandbox Code Playgroud) 我有公司表,其中每个公司都有单独的时区。例如 - 公司 1 的时区为 UTC+10,公司 2 的时区为 UTC+2
表companies具有字段 time_zone 和存储的区域缩写America/Los_Angeles(如果需要,我可以添加附加字段来存储 UTC 的偏移值)。
并具有带有 start_date 字段的表请求,其中存储了不带时区的 TIMESTAMP(UTC-0),例如 -
id | company_id | start_date (utc-0)
------------------------------------
1 | 1 | 21-03-16 02-00 // added for company `21-03-16 12-00`
2 | 2 | 21-03-16 23-00 // added for company `22-03-16 01-00`
3 | 1 | 20-03-16 13-00 // added for company `20-03-16 23-00`
4 | 1 | 21-03-16 23-00 // added for company `22-03-16 09-00
Run Code Online (Sandbox Code Playgroud)
我想要选择从 21-03-16 …
我正在使用以下代码在rails 3中设置AJAX操作.代码的AJAX部分似乎有效,但它没有请求正确的文件,我的respond_to为常规HTML提供服务.
路由信息:
resources :zones do
resources :records
end
Run Code Online (Sandbox Code Playgroud)
控制器:
def new
@zone = Zone.new
respond_to do |format|
format.html
format.js
end
end
Run Code Online (Sandbox Code Playgroud)
链接视图(haml):
= link_to 'Add a zone →', new_zone_path, :remote=>true
Run Code Online (Sandbox Code Playgroud)
从link_to生成的HTML(还注意到html实体的失败呈现......但这是另一个问题):
<a href="/zones/new" data-remote="true">Add a zone &#8594;</a>
Run Code Online (Sandbox Code Playgroud)
对于踢,视图/区域的目录列表.我不确定我这样做是否正确,所以我有new.js.rjs和new.rjs.它们都具有相同的内容,但从未被动作拾取.
| `~zones/
| |-_form.html.haml
| |-_record.html.haml
| |-edit.html.haml
| |-index.html.haml
| |-new.html.haml
| |-new.js.rjs
| |-new.rjs
| `-show.html.haml
Run Code Online (Sandbox Code Playgroud)
最后,从我点击链接时的服务器日志:
Started GET "/zones/new" for 127.0.0.1 at Wed Dec 29 00:04:03 -0700 2010
Processing by ZonesController#new as */*
User Load (0.4ms) SELECT "users".* …Run Code Online (Sandbox Code Playgroud) arduino ×1
c++ ×1
capybara ×1
crystal-lang ×1
date ×1
debian ×1
deployment ×1
factory-bot ×1
postgresql ×1
psql ×1
pty ×1
rjs ×1
rspec-rails ×1
rspec2 ×1
ruby ×1
ruby-1.9.3 ×1
rubygems ×1
timezone ×1