我一直在使用Rsense更新我的emacs配置,以允许在键入代码时出现自动完成下拉框.这在大多数文件中运行良好,除了我发现当我在ruby on rails项目中编辑一些代码时,它不允许我从表中选择答案.
这是我的设置:https: //github.com/map7/simple_emacs
我在Ubuntu 10.04下使用它.
对于简单的ruby脚本文件,它工作得很好.我可以打开一个新文件并输入.
"test".up...
Run Code Online (Sandbox Code Playgroud)
就像我输入'p'字符一样,出现了一个选项列表,我可以用箭头键在列表中上下移动,然后用回车键选择一个(例如:upcase).
什么不起作用是当我做一个完全相同的测试,但在rails项目的基本目录中.
更新:
发现问题在于(需要'rails),所以在emacs-rails插件中,自动完成不喜欢它.
更新:
它位于emacs-rails - > rails-project.el中.如果我评论这个宏,那么自动完成工作,否则它不会:
(defmacro* rails-project:with-root ((root) &body body)
"If you use `rails-project:root' or functions related on it
several times in a block of code, you can optimize your code by
using this macro. Also, blocks of code will be executed only if
rails-root exist.
(rails-project:with-root (root)
(foo root)
(bar (rails-core:file \"some/path\")))
"
`(let ((,root (rails-project:root)))
(when ,root
(flet ((rails-project:root () ,root))
,@body))))
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么这会打破自动完成吗?
我正在尝试在Angular中构建一个简单的计算器,我可以根据需要覆盖总计.我有这个部分工作,但当我然后返回输入一个或两个字段中的数字时,总数未在该字段中更新.
这是我的jsfiddle http://jsfiddle.net/YUza7/2/
表格
<div ng-app>
<h2>Calculate</h2>
<div ng-controller="TodoCtrl">
<form>
<li>Number 1: <input type="text" ng-model="one">
<li>Number 2: <input type="text" ng-model="two">
<li>Total <input type="text" value="{{total()}}">
{{total()}}
</form>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
javascript
function TodoCtrl($scope) {
$scope.total = function(){
return $scope.one * $scope.two;
};
}
Run Code Online (Sandbox Code Playgroud) 我正在使用带有capistrano的delayed_job,并希望使用'script/delayed_job start'启动网络应用程序时启动delayed_job.这样,capistrano可以在部署时重新启动它.如果服务器重新启动,那么我的delayed_jobs应该启动项目.
我怎样才能做到这一点?我应该在环境文件中还是作为初始化程序进行此操作?
我正在使用ruby 1.9而我正在尝试做BDD.我的第一个测试"应该在csv中读取",但是第二个我需要模拟文件对象的测试却没有.
这是我的型号规格:
require 'spec_helper'
describe Person do
describe "Importing data" do
let(:person) { Person.new }
let(:data) { "title\tsurname\tfirstname\t\rtitle2\tsurname2\tfirstname2\t\r"}
let(:result) {[["title","surname","firstname"],["title2","surname2","firstname2"]] }
it "should read in the csv" do
CSV.should_receive(:read).
with("filename", :row_sep => "\r", :col_sep => "\t")
person.import("filename")
end
it "should have result" do
filename = mock(File, :exists? => true, :read => data)
person.import(filename).should eq(result)
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是迄今为止的代码:
class Person < ActiveRecord::Base
attr_accessor :import_file
def import(filename)
CSV.read(filename, :row_sep => "\r", :col_sep => "\t")
end
end
Run Code Online (Sandbox Code Playgroud)
我基本上想要模拟一个文件,以便当CSV方法尝试从文件中读取时它返回我的数据变量.然后我可以测试它是否等于我的结果变量.
我最近将我的Heroku应用程序从Cedar-10升级到了Cedar-14,没有任何问题(仍然使用ruby 1.9.3).然后我尝试升级我的应用程序以使用ruby 2.0.0-p645并将其推送到heroku服务器.当我这样做时,我无法再访问我的应用程序,并在日志中收到以下错误;
2015-07-09T12:27:37.480991+00:00 app[web.1]:
2015-07-09T12:27:37.480996+00:00 app[web.1]: NoMethodError (undefined method `empty?' for nil:NilClass):
2015-07-09T12:27:37.480998+00:00 app[web.1]: app/controllers/wines_controller.rb:18:in `index'
2015-07-09T12:27:37.480999+00:00 app[web.1]:
2015-07-09T12:27:37.481001+00:00 app[web.1]:
2015-07-09T12:27:37.481462+00:00 app[web.1]: Processing by WinesController#index as HTML
2015-07-09T12:27:37.481465+00:00 app[web.1]: Completed 500 Internal Server Error in 100.1ms
Run Code Online (Sandbox Code Playgroud)
如果我看看wine_controller的第18行,我有以下几点;
respond_to do |format|
format.html
format.json {render json: @wines.as_json}
end
Run Code Online (Sandbox Code Playgroud)
我认为这是我的index.html中的内容,所以我把它拿回来了;
%h1 Wines
Run Code Online (Sandbox Code Playgroud)
在我的index.html.haml中只有这一行它仍然有问题.
如果我尝试访问wines.json这可以工作并给我一份我的葡萄酒清单.使用2.0.0在我的开发盒上运行工作正常,我的所有测试都通过了.
更新:在index.html上添加控制器和更多信息
这是我的葡萄酒控制器
def index
# Search via Ransack
@q = current_user.wines.includes(:wine_rack).unconsumed.order("LOWER(winery)").search(params[:q])
@wines = @q.result.page params[:page]
@total = @q.result.sum(:qty)
respond_to do |format|
format.html
format.json {render json: @wines.as_json}
end
end …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我创建的插件为rails创建一个ruby gem.问题是我的插件"快捷方式"使用了一些需要在public/javascripts目录中运行的javascript文件.
什么是制作这些javascript文件的最佳方法,这些文件位于我创建的gem中,可以访问哪个项目需要我的gem?
我正在我的Rails项目中使用Capybara selenium(在Ubuntu 10.04系统上)我现在刚刚运行我的测试firefox加载时升级了firefox但它现在已经安装了所有的附加组件,它等到我设置每一个都是第一次.
有没有办法在启动硒时禁用所有这些附加组件?
要么
有没有办法设置我的所有加载项并保存设置,以便每次运行测试时都不会提示我?
更新
如果我将其更改为使用铬,它可以正常工作.
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.javascript_driver = :selenium
Run Code Online (Sandbox Code Playgroud)
我想用firefox做测试.我在firefox下设置了一个'test'配置文件并尝试使用以下内容:
Capybara.register_driver :selenium_firefox_custom do |app|
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => "test")
end
Capybara.default_driver = :selenium_firefox_custom
Run Code Online (Sandbox Code Playgroud)
哪个不起作用,它仍然试图加载我的默认配置文件.
我正在使用水豚的git版本;
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用Capybara.javascript_driver =:selenium_firefox_custom
我正在使用Rails 3.2.3和money-rails gem,我有一个产品型号,其中包含以下内容:
我的模特
class Product < ActiveRecord::Base
attr_accessible :name, :price
composed_of :price,
:class_name => "Money",
:mapping => [%w(price_cents cents), %w(currency currency_as_string)],
:constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) },
:converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") }
end
Run Code Online (Sandbox Code Playgroud)
我的测试
require 'spec_helper'
describe Product do
context "testing money gem" do
it "creates product with price" do
product = Product.create(:price => 200)
product.price.should eq(200)
product.price_cents.should eq(20000)
end
end …Run Code Online (Sandbox Code Playgroud) 我想在我的rspec控制器测试中测试一名工作人员是否与公司相关联.
我想create在员工控制员的行动中最终得到这个:
staff.companies << current_company
Run Code Online (Sandbox Code Playgroud)
当current_company从一个会话变量收集.
我该如何为此编写测试?
我有这些型号
class Company < ActiveRecord::Base
has_many :employees
has_many :staff, :through => :employees
end
class Employee < ActiveRecord::Base
belongs_to :company
belongs_to :staff
end
class Staff < ActiveRecord::Base
has_many :employees
has_many :companies, :through => :employees
end
Run Code Online (Sandbox Code Playgroud)
以下测试是我尝试指定关联,当我输入关联代码时它失败:
it "should belong to the current_company" do
staff.should_receive(:companies)
post :create
end
Run Code Online (Sandbox Code Playgroud)
如果我在控制器中输入'staff.companies << current_company'代码,运行该测试时会出现此错误:
Failure/Error: post :create
NoMethodError:
You have a nil object when you didn't expect it!
You might have expected an instance …Run Code Online (Sandbox Code Playgroud) 我正在将Rails 3.1.3用于具有Inherited Resources 1.3.0的项目.
当我有这样的控制器时:
class PostsController < InheritedResources::Base
end
Run Code Online (Sandbox Code Playgroud)
我用rspec测试以下内容
describe "PUT update" do
describe "with invalid params" do
it "re-renders the 'edit' template" do
post = Post.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Post.any_instance.stub(:save).and_return(false)
put :update, {:id => post.to_param, :post => {}}, valid_session
response.should render_template("edit")
end
end
end
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
3) PostsController PUT update with invalid params re-renders the 'edit' template
Failure/Error: response.should render_template("edit")
expecting <"edit"> but rendering with <"">
# ./spec/controllers/posts_controller_spec.rb:115:in `block …Run Code Online (Sandbox Code Playgroud)