我注意到很多人更喜欢Mocha而不是RSpec内置的模拟框架.有人可以解释摩卡的优势,或任何替代方案,而不是RSpec内置的模拟框架?
我有一个ListBox,它的ItemTemplate绑定到DataTemplate.我的问题是我无法将模板中的元素拉伸到ListBox的整个宽度.
<ListBox x:Name="listPeople" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Margin="0,0,0,0" Background="{x:Null}" SelectionMode="Extended" Grid.Row="1"
ItemTemplate="{StaticResource PersonViewModel.BrowserDataTemplate}"
ItemsSource="{Binding Mode=OneWay, Path=SearchResults}" >
</ListBox>
<DataTemplate x:Key="PersonViewModel.BrowserDataTemplate">
<ListBoxItem HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,5,5,5">
<Border Opacity=".1" x:Name="itemBorder" Background="#FF000000"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
CornerRadius="5,5,5,5" MinWidth="100" Height="50"/>
</Grid>
</ListBoxItem>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
如您所见,我在网格中添加了一个边框以指示模板的宽度.我的目标是看到此边框扩展到列表框的整个宽度.目前它的宽度由其内容或MinWidth决定,这是目前保持可见的唯一内容.
假设我在rails应用程序的lib目录中有以下文件:
#lib/proxy.rb
module SomeService
class ServiceProxy
def do_something
end
end
end
Run Code Online (Sandbox Code Playgroud)
如果我想在模型中使用ServiceProxy,我可以像这样使用它:
#app/models/product.rb
require 'proxy'
class Product < ActiveRecord::Base
def do_something
proxy = SomeService::ServiceProxy.new
proxy.do_something
end
end
Run Code Online (Sandbox Code Playgroud)
这有效,但我注意到如果我想在另一个模型中使用ServiceProxy,我在第二个模型文件中不需要"require'proxy'".似乎在任何模型中都需要"require'proxy'"将其添加到查找路径中.
有人可以在rails应用程序中解释这种行为以及围绕它的最佳实践吗?
谢谢!
更新:根据下面的floyd的答案,如果我的ServiceProxy文件被保存为,
#lib/some_service/service_proxy.rb
Run Code Online (Sandbox Code Playgroud)
然后我不必明确要求该文件.
我遇到了JSON gem和Ruby 1.9.2的问题.我正在升级到Rails 3.0.3,每当我尝试启动环境时,它都会爆炸.这是一个空的测试项目,只有JSON gem 1.4.6作为依赖项.
/Users/lee/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/common.rb:66: [BUG] unknown type 0x22 (0xc given)
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
-- control frame ----------
c:0032 p:---- s:0096 b:0096 l:000095 d:000095 CFUNC :initialize
c:0031 p:---- s:0094 b:0094 l:000093 d:000093 CFUNC :new
c:0030 p:0085 s:0091 b:0089 l:000088 d:000088 METHOD /Users/lee/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/common.rb:66
c:0029 p:0090 s:0081 b:0080 l:000079 d:000079 CLASS /Users/lee/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/ext.rb:11
c:0028 p:0011 s:0078 b:0078 l:000077 d:000077 CLASS /Users/lee/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/ext.rb:6
c:0027 p:0021 s:0076 b:0076 l:000075 d:000075 TOP /Users/lee/.rvm/gems/ruby-1.9.2-p0/gems/json-1.4.6/lib/json/ext.rb:3
c:0026 p:---- s:0074 b:0074 l:000073 d:000073 FINISH
c:0025 p:---- …
Run Code Online (Sandbox Code Playgroud) 我跑的时候
rvm install 1.9.2
Run Code Online (Sandbox Code Playgroud)
尝试运行autoconf时出错.这是堆栈跟踪:
kenmare:ruby-1.9.2-p0 lee$ rvm install 1.9.2-p0
/Users/lee/.rvm/rubies/ruby-1.9.2-p0, this may take a while depending on your cpu(s)...
ruby-1.9.2-p0 - #fetching
ruby-1.9.2-p0 - #extracted to /Users/lee/.rvm/src/ruby-1.9.2-p0 (already extracted)
Running autoconf
Error running 'autoconf', please check /Users/lee/.rvm/log/ruby-1.9.2-p0/autoconf.error.log
Skipping configure step, 'configure' does not exist, did autoconf not run successfully?
ruby-1.9.2-p0 - #compiling
Error running 'make ', please check /Users/lee/.rvm/log/ruby-1.9.2-p0/make.error.log
There has been an error while running make. Halting the installation.
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢!
更新:对不起,它迟到了,并没有提供一些明显的信息.我在运行10.6.4的mac上.autoconf日志说:
autoconf: no input file
Run Code Online (Sandbox Code Playgroud)
关于make的答案,我跑的时候
which make …
Run Code Online (Sandbox Code Playgroud) 我最近注意到,如果我的测试子类为Test :: Unit :: TestCase,我的测试数据库在运行测试后没有被清理.如果我的测试子类是ActiveSupport :: TestCase,那么所有内容都会被正确清理.
任何人都可以解释为什么,和/或提供使用一个与另一个的解释?
我正在使用shoulda和factory_girl.
谢谢.
我试图从js.erb文件中访问实例变量.
#controller
def get_person
@person = Person.find(1)
respond_to do |format|
format.js{}
end
end
#get_person.js.erb
alert('<%= @person.last_name %>')
Run Code Online (Sandbox Code Playgroud)
当我浏览[controller_name_here] /get_person.js时......我在@person上得到一个nil对象错误.(我知道Person.find(1)返回一个对象)
注意:我实际上在我的js.erb文件中渲染部分时遇到问题,并且我正在尝试确定原因.
我正在寻找一个处理文件附件和图像大小调整的节点包.类似于paperclip和carrierwave宝石的东西.
我试图在模拟的ActiveRecord模型上设定期望值.我创建了以下示例,该示例应基于我可以找到的文档传递.
it "should pass given the correct expectations" do
payment = mock_model(Payment)
payment.should_receive(:membership_id).with(12)
payment.membership_id = 12
end
Run Code Online (Sandbox Code Playgroud)
它失败了,错误"......模拟'Payment_1004'收到了意外消息:membership_id = with(12)"
我意识到我正在测试模拟框架,我只是想了解如何设置期望.
我正在寻找允许我调整大小和上传图像水印的宝石.
我在ImageScience和Mini-Magick上看到很多帖子,但最近没什么.我正在寻找任何有助于我做出决定的经历.
ruby ×5
rspec ×2
rubygems ×2
ajax ×1
datatemplate ×1
factory-bot ×1
javascript ×1
json ×1
listbox ×1
mocking ×1
node.js ×1
ruby-1.9 ×1
rvm ×1
shoulda ×1
silverlight ×1