Attach files by dragging & dropping, selecting or pasting them. Uploading your files… We don’t support that file type. Try again with a GIF, JPEG, JPG, MOV, MP4, PNG, SVG or WEBM. Attaching documents requires write permission to this repository. Try again with a GIF, JPEG, JPG, MOV, MP4, PNG, SVG or WEBM. We don’t support that file type. Try again with a GIF, JPEG, JPG, MOV, MP4, PNG, SVG or WEBM.
私はRSpecでテストをこんな感じで書いてるという良エントリがあったので少し便乗してみます。 まずは上記の記事を。 最終的なrspecについてですが、私の場合は以下のような感じにしてます。 といっても、前回もかいたように試行錯誤の毎日です。 # -*- coding: utf-8 -*- require_relative 'user' describe User do describe "#admin?" do subject { user.admin? } let(:user) { User.new(role: role) } context "管理者の場合" do let(:role) { 'admin' } it { should be_true } end context "一般ユーザの場合" do let(:role) { nil } it { should_not be_tru
Cucumberって、仕様設計者の意図をプログラムによる自動テストにできる魔法です。 仕様設計者っていうのは、Rubyでのプログラミングが難しいけど、お客さまのニーズを理解して、それをドキュメントにできるハイパーな人です。プログラマにとっては神様です。 (でも、それがプログラマの徹夜の源なのだったりしますよね。実現が困難で意図が不明な仕様を必死で実装する感じですよね。だから、それをなんとかしなければ徹夜は解消できないと考えてみました。) Cucumberではプログラマ以外の人でも分かりやすい記述ができます。 でもね、どうせそのドキュメントを見るのはプログラマだけです。なので、生のCapybara APIで十分なのかもしれませんね。なので、ここではRSpecのfeature specを考察します。 from Feature spec on Relick : https://www.relis
rspec_rails_cheetsheet.rb ���6V P �6V #Model @user.should have(1).error_on(:username) # Checks whether there is an error in username @user.errors[:username].should include("can't be blank") # check for the error message #Rendering response.should render_template(:index) #Redirecting response.should redirect_to(movies_path) #Capybara Matchers response.body.should have_content("Hello world") respons
ある日突然「Rails 3 のプロジェクト作ったから Jenkins でテスト結果とカバレッジをいい感じで表示できるようにしておけよ」と言われて、一生懸命設定したときの内容をシェアする。 Scala (lift) 編は Jenkins で Scala (lift) プロジェクトのテスト結果とカバレッジをグラフ表示する - mallowlabsの備忘録 をご参照。 イメージ 環境 ruby 1.8.7 rubygems 1.5.0 rake 0.8.7 rails 3.0.3 ci_reporter 1.6.4 Jenkins 1.414 Jenkins ruby metrics plugin 1.5.0 Jenkins Rake plugin 1.7.6 まずはローカルで設定 要は rcov と ci_reporter を組み込んだ Rails 3 アプリケーションを作ればよい。 適当なブ
What is Better Specs Better Specs is a collection of best practices developers learned while testing apps that you can use to improve your coding skills, or simply for inspiration. Better Specs came to life at Lelylan (open source IoT cloud platform) and checking out its test suite may be of inspiration. Better Specs focus on Rails testing, but our goal is to create testing guidelines covering mos
(注: 以下の内容は、RSpec ユーザの間で広まっていることでもなく、もちろん RSpec 開発チームの公式な見解でもなく、あくまでワシの個人的な見解です。) RSpec のすごいところは、コードに対してではなく仕様に対してテストを書くことを明確にしたことだと思う。何を今さらと言われそうだけど、今さらになってようやく気づいたニワトリ頭ですまんかった。 ワシも最初は、「assert_equal(expected, actual)」のかわりに「actual.should == expected」と書くかっこよさに目を奪われて、テストコードを自然言語に近い形で記述するのが RSpec のすごいところだと勘違いしてたし、それが「TDD (Test Driven Development)」から「BDD (Behaviour Driven Development)」へという新しい潮流だと勘違いしてた
ちょっと前に話題になったRSpecのスライドがステキだったよね。でもRSpecはまだまだ底知れない気がするので自分でもいろいろと調べてみようと思った次第。 まずはrspec-core(2.5.1)/features/example_groups/shared_example_group.featureを参考にshared example groupについて調べてみたよ。 例1:テストを共有できる require "set" shared_examples_for 'a collection' do subject { described_class.new [7, 2, 4] } its(:size) { should eq 3 } it { should include 7 } it { should_not include 9 } end describe Array do it_be
すでに前回のすごいぞRSpec(shared example group編) - ぷろぐらまねがで登場してるけどあらためてletを調べるよ。rspec-core(2.5.1)/features/helper_methods/let.featureを参考に。 let 要するにメモ化するわけで、同一サンプル内だと同じオブジェクトを使いまわせるのだな。違うサンプルでは改めて評価される。さらに遅延評価なので実際に評価されるのは最初にメソッドが呼ばれたときだ。 $count = 0 describe 'let' do let(:count) { $count += 1 } it 'memoizes the value' do count.should == 1 count.should == 1 end it 'is not cached across examples' do count.shou
In a Rails 3 application I have a domain class where one attribute stores pure HTML content (it's a blog app, the domain class is Post). In the ERB templates, I need to display the content of the attribute as it was formmated, with the HTML tags in place. But, Rails is escaping all HTML tags! How can I disable this behaviour for this class attribute? Example: somePost = Post.new somePost.content =
五十嵐(igaiga)です。 Rails3でRSpecを使おうとしてはまったので日記を書きます。 Gemfile へ以下のように書いて gem 'rspec-rails' bundle install するとRSpec1系がインストールされてしまいます。(2010.9.8現在) Rails3ではRSpec2系を使いたいので、以下のように書き直してみたのですが、 gem 'rspec-rails', '>= 2.0.0' 今度は2.0.0はまだリリースされていないと言われます。 ベータバージョンを明に書くのは嫌だな、と思ったら、ursmさんのページに以下のような記述が。 gem 'rspec-rails', '>= 2.0.0.beta' これで最新のRSpec2系beta版がインストールされるようになりました。 あとは bundle install rails g rpsec:instal
rspec-core provides the structure for RSpec code examples: describe Account do it "has a balance of zero when first opened" do # example code goes here - for more on the # code inside the examples, see rspec-expectations # and rspec-mocks end end Issues The documentation for rspec-core is a work in progress. We'll be adding Cucumber features over time, and clarifying existing ones. If you have spe
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く