我有这个型号
class User < ActiveRecord::Base
after_create :create_in_remote
def create_in_remote
if self.remote_id.nil?
req_url = "api/create/user/#{self.username}"
response = Remote.execute_request(req_url)
if response
self.update_attribute(:remote_id, response["id"]) if response["id"]
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
在我的规范中我尝试这样做
require 'spec_helper'
describe User do
before { @user = FactoryGirl.build(:user) }
subject { @user }
it "has_remote_id" do
@user.save! && @user.reload
expect(@user.remote_id).not_to be_nil
end
end
Run Code Online (Sandbox Code Playgroud)
但从未通过测试,但对象始终在远程 api 上创建。如果我想查看@user对象的属性remote_id的值始终为null。如果我将构建更改为在工厂中创建,我可以在日志中看到属性已更新,但在测试中使用时它为空并且测试失败。
我在Mac OS 10.7.5上使用rvm和ruby 1.9.3.
我希望能够使用Sublime Text 2 RubyTest包来验证我的Ruby语法.
但是,当我尝试Tools -> RubyTest -> Verify Ruby Syntax在任何ruby文件(test.rb下面)上运行时,RubyTest控制台中会显示以下错误:
/Users/jladieu/.rvm/rubies/ruby-1.9.3-p194/bin/ruby:1:无效的多字节字符(US-ASCII)
我的test.rb文件内容很简单:
class Test
def hello
puts "Hello world"
end
end
Run Code Online (Sandbox Code Playgroud)
我的RubyTest.sublime_settings文件如下:
{
"erb_verify_command": "erb -xT - {file_name} | ruby -c",
"ruby_verify_command": "ruby -c {file_name}",
"run_ruby_unit_command": "bundle exec ruby -Itest {relative_path}",
"run_single_ruby_unit_command": "bundle exec ruby -Itest {relative_path} -n '{test_name}'",
"run_cucumber_command": "zeus cucumber {relative_path} --no-color",
"run_single_cucumber_command": "zeus cucumber {relative_path}:{line_number} --no-color",
"run_rspec_command": "zeus rspec {relative_path}",
"run_single_rspec_command": "zeus rspec {relative_path}:{line_number}", …Run Code Online (Sandbox Code Playgroud) 我正在使用 ruby 编写一个测试,其中我按照下面的代码验证一些数据。
\n\narray['myLabel'].should eq '(100\xe2\x80\x93200) mg/dL'\nRun Code Online (Sandbox Code Playgroud)\n\n当我运行测试时,我在这一行收到错误。
\n\n错误是:invalid multibyte char (US-ASCII)然后在下面syntax error, unexpected $end, expecting keyword_end
我检查了测试并确保我到处都有正确的结束语句。但当我执行测试时仍然出现这些错误。
\n\n我是红宝石菜鸟。如果我遗漏了什么,请提出建议。
\n