我遇到了一个问题,我想确认我正在以正确的方式做事.
我可以使用SenTestingKit测试测试简单的东西,这样可以正常工作.我已经设置了一个单元测试包并将其设置为对主应用程序目标的依赖.每按一次cmd + B,它都会成功运行所有测试.
这是我遇到问题的地方.我有一些XML文件,我需要从资源文件夹加载作为应用程序的一部分.作为一个优秀的单元测试人员,我想围绕这个进行单元测试,以确保它们正确加载.
所以我有一些看起来像这样的代码:
NSString *filePath = [[NSBundle mainBundle]
pathForResource:@"foo" ofType:@"xml"];
Run Code Online (Sandbox Code Playgroud)
这在应用程序运行时有效,但在单元测试期间,mainBundle指向错误的包,因此这行代码返回nil.
所以我把它改为使用这样一个已知的类:
NSString *filePath = [[NSBundle bundleForClass:[Config class]]
pathForResource:@"foo" ofType:@"xml"];
Run Code Online (Sandbox Code Playgroud)
这也不起作用,因为为了使测试甚至像这样编译代码,它Config需要成为单元测试目标的一部分.如果我添加,那么该类的包将成为单元测试包.(啊!)
我是以错误的方式接近这个吗?
我有一个UILabel我想要启用放大的多行.
我用a嵌入它UIScrollView并设置最小缩放到.25和最大缩放到4.这很好用,但是我UILabel的字体在除1以外的任何缩放级别看起来相当粗略.
我可以处理这个方法:
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
Run Code Online (Sandbox Code Playgroud)
为了将我的UILabel的字体重新调整为更大的尺寸,但视图仍然放大,所以它看起来总是很糟糕.
有没有办法让标签的文字重新渲染一个我完成缩放?
重要的是用户当前在文本中滚动的位置不会丢失.
(为了了解我的目标,请注意在移动Safari中缩放文本时如何缩放/消除锯齿一瞬间然后它会在您当前的缩放比例下清晰显示)
我在表单上有一个复选框列表.由于CSS的结构方式,标签元素直接设置样式.这需要我将复选框嵌套在标签内.
这适用于原始HTML,如果单击标签文本,则复选框的状态会发生变化.<%= f.check_box %>但是,它不适用于rails helper,因为它首先输出隐藏的输入标记.
综上所述,
<label>
<%= f.check_box :foo %>
Foo
</label>
Run Code Online (Sandbox Code Playgroud)
这是我想要的输出:
<label>
<input type="checkbox" ... />
<input type="hidden" ... />
Foo
</label>
Run Code Online (Sandbox Code Playgroud)
......但是这就是Rails是给我:
<label>
<input type="hidden" ... />
<input type="checkbox" ... />
Foo
</label>
Run Code Online (Sandbox Code Playgroud)
所以标签行为实际上并不起作用:(.
有没有办法解决这个问题?
我在将Ruby连接到Microsoft SQL Server时遇到了麻烦.我正在运行Mac OS X,但目标环境是Ubuntu Linux.
这是我尝试过的:
然后我将这些文件放在/usr/local/etc:
odbc.iniodbcinst.inifreetds.conf我在odbcinst.ini文件中将FreeTDS驱动程序的引用添加到我的ODBC驱动程序文件中,如下所示:
;
; odbcinst.ini
;
;
[FreeTDS]
Driver = /usr/local/lib/libtdsodbc.so
Run Code Online (Sandbox Code Playgroud)
然后我在freetds.conf文件中配置服务器,如下所示:
# Aries database server (SQL Server 2008)
[aries-db1]
host = xx.xx.xx.xx
port = 1433
tds version = 8.0
Run Code Online (Sandbox Code Playgroud)
最后我在odbc.ini文件中添加了ODBC DSN,如下所示:
[aries-db1]
Driver = FreeTDS
Description = ODBC Connection via FreeTDS
Trace = 1
Servername = aries-db1
Database = MY_DB
UID = user1
PWD …Run Code Online (Sandbox Code Playgroud) 在新机器上,使用Windows的1-click安装程序安装ruby.安装了rails 2.3.2和所有相关的gem,然后我安装了sqlite3二进制文件(进入c:\ ruby\bin文件夹).最后我做了gem install sqlite3-ruby -v=1.2.3(这显然是与Windows一起使用的最新版本)
运行时rake db:migrate或在运行时触摸任何ActiveRecord对象时会发生此错误.
错误如下所示:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
**uninitialized constant Encoding** <----
Run Code Online (Sandbox Code Playgroud)
任何帮助解决此错误将不胜感激!
跟踪:
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:443:in `load_missing_constant'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in `const_missing'
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:92:in `const_missing'
C:/Ruby/lib/ruby/gems/1.8/gems/sqlite3-0.0.3/lib/sqlite3/encoding.rb:9:in `find'
C:/Ruby/lib/ruby/gems/1.8/gems/sqlite3-0.0.3/lib/sqlite3/database.rb:69:in `initialize'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `new'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `sqlite3_connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `loop'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `checkout'
C:/Ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:435:in `initialize'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:400:in `new'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:400:in `up'
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/migration.rb:383:in …Run Code Online (Sandbox Code Playgroud) 当我将UITableViewCells设置为backgroundColor半透明颜色时,它看起来不错,但颜色并不覆盖整个单元格.
周围的区域imageView和accessoryView涌现出来的[UIColor clearColor]...

我已经尝试明确设置cell.accessoryView.backgroundColor和cell.imageView.backgroundColor与单元格相同的颜色backgroundColor,但它不起作用.它在图标周围放置一个小盒子,但不会扩展以填充左边缘.右边缘似乎不受此影响.
我怎样才能解决这个问题?
编辑:这是原始表格单元格代码:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.opaque = NO;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha:.4];
cell.textColor = [UIColor whiteColor];
}
cell.imageView.image = [icons objectAtIndex:indexPath.row];
cell.textLabel.text = [items objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; …Run Code Online (Sandbox Code Playgroud) 我刚刚进入工厂女孩,我遇到了一个困难,我肯定应该更容易.我只是无法将文档扭曲成一个有效的例子.
假设我有以下型号:
class League < ActiveRecord::Base
has_many :teams
end
class Team < ActiveRecord::Base
belongs_to :league
has_many :players
end
class Player < ActiveRecord::Base
belongs_to :team
end
Run Code Online (Sandbox Code Playgroud)
我想要做的是:
team = Factory.build(:team_with_players)
Run Code Online (Sandbox Code Playgroud)
让它为我建立一堆球员.我试过这个:
Factory.define :team_with_players, :class => :team do |t|
t.sequence {|n| "team-#{n}" }
t.players {|p|
25.times {Factory.build(:player, :team => t)}
}
end
Run Code Online (Sandbox Code Playgroud)
但这:team=>t部分失败了,因为t它不是真的Team,它是一个Factory::Proxy::Builder.我必须将一个团队分配给一名球员.
在某些情况下,我想建立一个League并让它做类似的事情,创建多个拥有多个玩家的团队.
我错过了什么?
我正在尝试过渡到MacVim for ruby dev.我所拥有的一个问题是快速运行规范并轻松获得结果(通过/失败).
当我运行:Rake(或:!rspec %)它运行当前文件中的规范.输出显示在命令窗口中.
如果我在常规终端中运行它,我会得到彩色输出.也就是说,点是绿色的,故障是红色的.
在MacVim中,我得到了这些奇怪的[32m和[0m令牌.这是一个例子:

有想法该怎么解决这个吗?
您知道一些bug跟踪器(和其他软件)如何允许您添加自定义字段?
通常,这是通过如下所示的数据结构完成的:
Items
----------
ID | NAME | ITEM_TYPE_ID
FieldDefinitions
---------------------------------------
ID | ITEM_TYPE_ID | FIELD_NAME | FIELD_TYPE
FieldValues
---------------------------------------
ID | FIELD_ID | ITEM_ID | VALUE
Run Code Online (Sandbox Code Playgroud)
我试图找出在Rails中实现这种设计的最佳方法.我想要允许扩展简单属性的许多模型.
当我进行检索时,Item我希望它包含已为该模型定义的加法字段值的哈希值.
我写了一段Rack Middleware来自动解压缩压缩的请求体.代码似乎工作正常,但是当我将它插入我的rails应用程序时,我从ActionController :: ParamsParser获得了"Invalid JSON"失败.
作为一种调试机制,我正在将压缩内容和解压缩的内容写入文件(以确保代码正常工作),并且我确实收到了原始的JSON文档(在客户端将其拉出之前).
我发布的数据是 JSON数据,解压缩的内容被检测为来自http://jsonlint.com的有效JSON .
我有什么想法我做错了吗?
class CompressedRequests
def initialize(app)
@app = app
end
def call(env)
input = env['rack.input'].read
#output the zipped data we received
File.open('/Users/ben/Desktop/data.gz', 'w+') do |f|
f.write input
end
if env['REQUEST_METHOD'] =~ /(POST|PUT)/
if env.keys.include? 'HTTP_CONTENT_ENCODING'
new_input = decode(input, env['HTTP_CONTENT_ENCODING'])
env['rack.input'] = StringIO.new(new_input)
#output our decoded data (for debugging)
File.open('/Users/ben/Desktop/data.txt', 'w+') do |f|
f.write env['rack.input'].read
end
env.delete('HTTP_CONTENT_ENCODING')
end
end
env['rack.input'].rewind
status, headers, response = @app.call(env)
return [status, headers, response]
end …Run Code Online (Sandbox Code Playgroud) ruby ×4
iphone ×3
unit-testing ×2
activerecord ×1
bundle ×1
factory-bot ×1
freetds ×1
html ×1
macvim ×1
middleware ×1
objective-c ×1
odbc ×1
rack ×1
rspec ×1
sql-server ×1
sqlite ×1
sqlite3-ruby ×1
uilabel ×1
uiscrollview ×1
uitableview ×1
unixodbc ×1
vim ×1
windows ×1
xcode ×1