結構バージョンアップに苦労したため、メモ。 注意点は2点 ZenTestからautotest-rails部分が切り離された→別々にgemでインストールする必要がある なぜかautotest/redgreen等のプラグインが大幅に削除されている→旧バージョンからコピーして対応 ZenTest最新版インストール ※この時点ではVer4.1.3がインストールされた。 $ gem install ZenTest autotest-railsインストール $ gem install autotest-rails 各種プラグインコピー 旧バージョンZenTestのフォルダからプラグインを持ってくる。 ※既に存在するファイルは上書きしないほうが良さそう。 gemフォルダ/ZenTest-4.0.0/lib/autotest → gemフォルダ/ZenTest-4.1.3/lib/autotest 旧バー
http://developer.mixi.co.jp/appli/make_request/validating_signed_requests これのRails版。 http://mixiapp.ssktkr.com/ class TopController < ApplicationController def index end MIXI_CERTIFICATE = <<END -----BEGIN CERTIFICATE----- MIICdzCCAeCgAwIBAgIJAOi/chE0MhufMA0GCSqGSIb3DQEBBQUAMDIxCzAJBgNV BAYTAkpQMREwDwYDVQQKEwhtaXhpIEluYzEQMA4GA1UEAxMHbWl4aS5qcDAeFw0w OTA0MjgwNzAyMTVaFw0xMDA0MjgwNzAyMTVaMDIxCzAJBgN
Rackとは、Rubyで実装したアプリケーションとウェブサーバとを繋ぐインターフェースです。Rackプロトコルに従って実装したアプリケーションは、利用するウェブサーバを自由に選択する事が可能となります。 Rackの開発元へは、以下のリンクから。 Rack: a Ruby Webserver Interface Rackプロトコルについて、簡単に説明します。 Rackプロトコルに従ったアプリケーションとは、環境変数envを引数にとるメソッドcallを持つRubyオブジェクト(インスタンス)を意味します。callは、3つの要素を持つArrayオブジェクトを返します。これは順に、『HTTPステータスコード』『HTTPレスポンスヘッダ』『HTTPボディ』となります。 環境変数 アプリケーションは、環境変数を読み書きする事で、入出力操作等を行える様になります。環境変数は、いわゆるCGI環境変数や、R
スクレイピングのチュートリアルを書いてみた。 参考:http://nokogiri.rubyforge.org/nokogiri/Nokogiri.html まだまだたくさんのクラスやメソッドがあるが(読んでない)、HTMLのスクレイピングに限定すれば多分これくらいで十分。 2014-02-16追記 なんかたくさんブックマークされていることに気づいたので、サンプルコードのRuby1.9/2対応のアップデート。 Mechanize周りも修正。WWW::Mechanize → Mechanize 等 (0) 前提知識 Ruby、HTML、DOM、CSSセレクタまたはXPath (1) クラス構造の理解 Nokogiri::HTML::Document < Nokogiri::XML::Document < Nokogiri::XML::Node < Object Nokogiri::XML::
Ruby on Rails のMetalを使ったコードのテストですが、RailsのIntegrationTestでテストできます。→ここを参照 しかし、一度RSpecを知ってしまうと従来のUnitTestには戻れません ^^); そこで Rack用のテスティングフレームワーク Rack::Test を使えば RSpec で Metal のテストが書けそうだと思い試してみました。 require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) class Hello def self.call(env) request = Rack::Request.new(env) if env["PATH_INFO"] =~ /^\/hello/ [200, {"Content-Type" => "
仕事で作っているRailsアプリにCucumberを突っ込んでみました。これは熱い。いやもう十分、お客さんに見せて分かってもらえる気がします。たぶん。もちろん準備は必要だし、受け入れ仕様をすべてお客さんに書いてもらうというのは難しいですけど*1。 とりあえず導入はこちらから。最近はNokogiriが必要です。あとTerminal.appで--no-colorつけずに実行するとTerminal.appがひどいことになるのでiTermお薦めです。 http://github.com/aslakhellesoy/cucumber/wikis/ruby-on-rails 2010-11-10 SEO的に。この記事を書いてから2年、いろんなCucumberの使い方を調べました。そのノウハウを達人出版会にて本にまとめました。よろしければこちらもどうぞ。 http://tatsu-zine.com/bo
今流行りつつある話題のCucumberとWebratをRailsで使ってみました。 CucumberとWebratなんぞやという人はid:moroさんの「 Cucumberがアツい」が参考になります。 今回やったこと RailsにCucumberを入れてみた Featureの予約語を日本語にして動かしてみた Cucumberをautotestでも動くようにしてみた autotestの結果をGrowlに通知するようにしてみた 参考サイト 上記のCucumberがアツい Cucumberのgithub 必要なパッケージのインストール 以下のgemが必要みたいなので、まだインストールしていない場合はインストールします。 rspec rspec-rails cucumber webrat term-ansicolor treetop diff-lcs nokogiri ZenTest(autote
のかな 22:23:11 ma2> @wtnabe gemを使わないとダメなんじゃないでしょうか。 22:25:20 wtnabe< @ma2 えっと、require_gem でできるってことですか? 22:30:49 wtnabe< あー Kernel#gem か。なるほど。 23:15:35 wtnabe< @ma2 gem 'GEM_NAME', 'version'; require 'GEM_NAME' で すね。ありがとうございます。 $ ri Kernel#gem ------------------------------------------------------------- Kernel#gem gem(gem_name, *version_requirements) -------------------------------------------------
Railsを使っている方も、使っていない方もこんにちは。この特集では、「Rails2.0の足回りと中級者への道」と題して、2007年12月7日にリリースされたRails2.0の基礎と、Rails2.0が提示する新しいアプリケーションの形、について学んでいきたいと思います。 Rails2.0とは何か? Railsの開発者David Heinemeier Hansson(DHH)自身が語るように、Rails2.0は「革命的というより漸進的(“evolutionary rather than revolutionary”)」なリリースです。バージョンの数値の変化とはうらはらに、Rails1.1とRails1.2間に行われたほどの変革はありません。 ですが、痛みすら伴う数多くの洗練と、RESTfulなアプリケーションへの傾倒を含んだリリースになっています。 この特集ではまず、Rails
Nokogiriは実在するぶっ壊れたHTMLでもパースできるらしい。 Nokogiri.parseはヒューリスティックにHTMLかXMLかを判断して、合ったパーサを使うようになっている。でもHTMLだとわかっている場合はNokogiri::HTML.parseと明示したほうがよい。nokogiri.rbより引用。 module Nokogiri class << self ### # Parse an HTML or XML document. +string+ contains the document. def parse string, url = nil, encoding = nil, options = nil doc = if string =~ /^\s*<[^Hh>]*html/i # Probably html Nokogiri::HTML.parse(string,
織田信長 ぼちぼち、元気にやっています。少し薬にも慣れた...んかなぁ。相変わらず食べられないけど。朝、指がこわばって文字なんて入力できなかったけど、それはほぼなくなった。関節もどこも痛くない。薬効いてきたんやろな。 で、ブログを書こうと言う気がまた起きてきた。 …
「怠慢はプログラマの美徳」というけれど - kなんとかの日記 俺がJavaに萌えない理由を100%代弁してくれている。それはさておき、 data = [ {'name'=>'Foo', 'age'=>20, 'email'=>'foo@mail.com'}, {'name'=>'Bar', 'age'=>21, 'email'=>'bar@mail.net'}, {'name'=>'Baz', 'age'=>22, 'email'=>'baz@mail.org'}, ] うむ、たしかに冗長だ… だけど3つくらいならそのまま書くかもしれない。多くなると俺は「怠惰」だからmapとStruct使う。 require 'pp' [ ['Foo', 20, 'foo@mail.com'], ['Bar', 21, 'bar@mail.net'], ['Baz', 22, 'baz@mail.org'
Rubyのハッシュのアクセスを手抜きする方法 | おごちゃんの雑文 それはいいんだけど、こいつはJSONをハッシュに変換する。データがアクセス出来れば結局は 何でもいいのだけど、深い階層を持ったデータだとアクセスがなかなか面倒臭い。Rubyで構造 付きのものを扱うのはハッシュにするのが定石らしいのだけど、階層が深くなると面倒になる 。 hash['a']['b']['c'] みたいになるのは、キー入力が厄介。プログラム中でアクセスするのは別にどうってことない のだけど、即値があると面倒。みんなはどうしてるか知らないけど、面倒臭いなーと思ってい た。 そこで、これを、 hash.a.b.c のようにアクセスする方法を考えた。 method_missingはおすすめできない。既存のメソッドとたまたまかぶってしまったらハマる。 アクセサ好きならば構造体がよい。一旦根っこを構造体にしてしまえば、あ
pure-rubyのシンプルなデータベース。インストールの必要がなく手軽に扱える。 注意 本ドキュメントは KirbyBase Version 1.6 用です。 最新版の Version 2.2 では、仕様が変更されているようです。 ダウンロード KirbyBaseから、Download KirbyBase 1.6 for Ruby(KirbyBase_Ruby_1.6.zip)をダウンロードする。 インストール ダウンロードしたファイルを展開し、KirbyBaseを使用するプログラムと同じフォルダにkirbybase.rbをコピーする。 使用方法 KirbyBaseをロードする。 require 'kirbybase' インスタンスを作成する 引数を指定しない場合は、シングルユーザーモードでになる。 db = KirbyBase.new serverを引数にすると、マルチユーザーモードに
「SQLiteが入ってないレンタルサーバーでSQLiteを動かす計画(敗北編)」では、SQLiteをアプリごと配置しようとして失敗しました。失敗の原因はglibcのバージョンの不整合です。要するにC言語で書かれたライブラリにアクセスしようとしたのが間違いだったわけです。 それならばC言語を使わずにRubyだけでデータベースを作ってしまおうと思いつきました。Rubyにはファイルにアクセスするインターフェイスがあるので、実現はできそうです。でもその前に、既にRubyで作られたデータベースが存在するのではないかと思い、検索してみました。 そして見つけたのがpure Rubyのデータベース"KirbyBase"です。それほどメジャーではないようです。ダウンロードページを見つけるだけでも苦労しました。下のページからダウンロードできます。Python製のデータベースもあるようですね。 Page not
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く