夜鸣猪的Ruby On Rails 空间
夜鸣猪 · 共 628 篇文章
如何在Cucumber下运行ruby-debug
# Gemfile group :development, :test do # ... other gems here gem 'ruby-debug19', :require => 'ruby-debug' end # features/support/env.rb require 'ruby-debug' # features/step_definitions/some_definitions.rb Then /^I debug$/ do debugger end http://www.robl.me/posts/i18n-translations-with-a-database-ba…
2012-04-07 00:19 · Ruby On Rails · Ruby 1.9 · 评论(0)
Cucumber Capybara Selenium 如何触发一个dom的点击事件
就是 click_on 和 Press 只能针对button和link如果,有个页面元素是,javascript绑定的怎么触发 page.execute_script("$('#{css_selector}').trigger('click')") page.find('#element').trigger(:mouseover) page.execute_script("$('#{css_selector}').trigger('focus')") page.execute_script("$('#{css_selector}').trigger('hover')") 学习地方 API地址…
2012-04-06 12:50 · Ruby On Rails · Ruby 1.9 · 评论(0)
很多^M在代码行的后面
在git diff的时候发现 可能是Windows开发工具搞上来的,因为有不一样的换行回车 解决办法是 vim :set fileformat=unix :%s/^M//g :%s/\r//g :w dos2unix perl -pie 's/\r//g' filename.txt sed s/\r// hello.txt > helloUNIX.txt dos2unix hello.txt helloUNIX.txt cat hello.txt | tr -d \r > helloUNIX2.txt
2012-04-06 05:11 · 评论(0)
升级rails 3.2.3时候快速解决的小问题
uninitialized constant Test::Unit::TestCase::Assertions (NameError) 解决办法是处理一下spec_helper ENV["rails_env"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' #require 'capybara' require 'capybara-webkit' require 'capybara/rspec' #require 'rspec/autorun' #…
2012-04-06 05:06 · Ruby On Rails · Ruby 1.9 · 评论(0)
Ruby 1.9.3 p125 安装ruby-debug
Update: 4/10/2012 直接换成 gem 'debugger' 老的ruby-debug更新有点慢啊 跑起来一模一样 运行下面的shell安装新版gem # Install with: # bash < <(curl -L https://raw.github.com/gist/1891192) # # Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug echo "Installing ruby-debug with ruby-1.9.3-p125 ..." curl -OL http:…
2012-04-05 00:50 · Ruby On Rails · Ruby 1.9 · 评论(0)
Rails在link_to中加参数
首先,说明post,get不一样 其次 link_to 'Link', request.parameters.merge({:per_page => 20}) link_to 'Link', params.merge({:per_page => 20}) link_to 'Whatever', :overwrite_params => { :pear_page => 20 } link_to "some_other_link", "/search", :page => params[:page]
2012-03-28 08:23 · Ruby On Rails · 评论(2)
用RSPEC测试路由
基本 require "spec_helper" describe "routes for Widgets" do it "routes /widgets to the widgets controller" do { :get => "/widgets" }. should route_to(:controller => "widgets", :action => "index") end end { :delete => "/accounts/37" }.should_not be_routable require "spec_helper" describe "routes for W…
2012-03-28 08:20 · Ruby On Rails · 评论(1)
如何在model里使用view helper
class Glosentry < ActiveRecord::Base include ActionView::Helpers::TextHelper def short_explanation(len=20) truncate(self.explanation, len) end end 上面的方法虽然可以用但,逻辑上并不好,因为Model不是helper,所以可以用下面的方法 class Glosentry < ActiveRecord::Base class GlosentryHelper include ActionView::Helpers::TextHelper end def…
2012-03-28 07:58 · Ruby On Rails · 评论(0)
Cucumber 关于路径的definition
I go to the edit movie page for "Alien" 主要为了能够通用 When /^(?:|I )go to (.+)$/ do |page_name| visit path_to(page_name) end def path_to(page_name) case page_name when /^the home\s?page$/ '/' when /^the (.*)\s?page for (.*)\s?$/ page_name.scan /^the (.*)\s?page for "(.*)"$/ path_components = $1.split(/\…
2012-03-25 00:48 · Ruby On Rails · 评论(0)
cucumber test 小心得 二
Scenario: Signing up Given I am on the homepage When I follow "Sign up" And I fill in "Email" with "user@ticketee.com" And I fill in "Password" with "password" And I fill in "Password confirmation" with "password" And I press "Sign up" Then show me the page Then I should see "You have signed up suc…
2012-03-17 02:10 · Ruby On Rails · 评论(0)
cucumber test 小心得
最近,有时间在参考UC berkeley一个免费在线Ruby学习课程 https://www.coursera.org/saas/class/index 写了点Cucumber测试有些心得 When /^I make all my stuff shiny$/ step "I polish my first thing" end When /^I make all my stuff shiny$/ steps %Q{ When I polish my first thing When I shine my second thing } end 如果有如下的类似错误,是因为使用了steps Th…
2012-03-17 02:07 · Ruby On Rails · 评论(0)
关于block和闭包的练习
关于block和闭包的练习 def example(num) puts puts "------ Example #{num} ------" end example 1 def thrice yield yield yield end x = 5 puts "value of x before: #{x}" thrice { x += 1 } puts "value of x after: #{x}" example 2 def thrice_with_local_x x = 100 yield yield yield puts "value of x at end of thrice_w…
2012-03-06 11:25 · Ruby 1.9 · 评论(0)
Rails 3 的 scope
在rails 2中关联俩个表时如下用: User.find( :all, :joins => :profile, :conditions => ['profile.age = ?', 33]) 在rails 3中变成如下 User.joins(:profile).where('profile.age = ?', 33) 区别在于,后者可以跟each,all,count, first query = User.joins(:profile).where('profile.age = ?', 33) query.where('users.name = ?', name) unless name.…
2012-03-06 11:08 · Ruby On Rails · 评论(0)
yield可以在block中吗?
类似如下的实现 a = lambda { puts 'in a' yield if block_given? } a.call { puts "in a's block" } 上面的调不到,使用如下: #ruby 1.8 a = lambda { |my_proc| puts 'in a' my_proc.call } a.call(lambda { puts "in a's block" }) #Ruby 1.9 a = lambda { |&block| puts 'in a' block.call } a.call { puts "in a's block" }
2012-03-06 10:58 · Ruby On Rails · Ruby 1.9 · 评论(0)
ruby block的用途和理解
在论坛讨论问题,自己写体会抄回来 常用到的场合: scope 当需要动态参数时 scope :aged_0, lambda{ where("created_at IS NULL OR created_at < ?", Date.today + 30.days).joins(:owner) } scope :aged_1, lambda{ |d_time|where("created_at IS NULL OR created_at < ?", d_time).joins(:owner) } rspec测试 lambda{post :create, :user => @attr}.should…
2012-03-05 00:19 · Ruby On Rails · 评论(1)