Rails3 Cucumber no.3

  • Terminal 起動
  • $ cd rails3/rails3_cucumber/
  • add Japanese scenario
    • $ vim features/messages.feature

シナリオ: ××すると、△△される
前提 □□している
もし ●●する
かつ ▲▲する
ならば ■■されていること

    • $ rake cucumber

(::) failed steps (::)


Could not find field: "●●" (Webrat::NotFoundError)
./features/step_definitions/web_steps.rb:36:in `/^(?:|I )fill in "([^"]*)" with "([^"]*)"$/'
features/messages.feature:16:in `もし●●する'


Failing Scenarios:
cucumber features/messages.feature:14 # Scenario: ××すると、△△される


ja:
2 scenarios (1 failed, 1 passed)

    • For error
      • $ vim config/locales/ja.yml

ja:
 activerecord:
  models:
   message: "□□"


  attributes:
   message:
    text: "●●"


 railties:
  scaffold:
   create: "▲▲"

      • $ vim app/views/messages/_form.html.erb

<%= f.submit t(:create, :default => "Create", :scope => [:railties, :scaffold]) %>

      • $ rake cucumber

(::) failed steps (::)


Could not find field: "Text" (Webrat::NotFoundError)
./features/step_definitions/web_steps.rb:36:in `/^(?:|I )fill in "([^"]*)" with "([^"]*)"$/'
features/messages.feature:10:in `もし●●する'


Failing Scenarios:
cucumber features/messages.feature:8 # Scenario: ××すると、△△される


2 scenarios (1 failed, 1 passed)
8 steps (1 failed, 2 skipped, 5 passed)

      • For error
        • $ vim features/messages.feature

前提 言語は"en-US"


前提 言語は"ja-JP"

        • $ vim features/step_definitions/web_steps_ja.rb

前提 /^言語は"([^"]*)"$/ do |lang|
 header('ACCEPT_LANGUAGE', lang)
end

        • $ vim app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
before_filter :set_locale


private
def set_locale
if request.env['HTTP_ACCEPT_LANGUAGE']
locale = (request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first || I18n.locale)
I18n.locale = locale
end
end


end

        • $ rake cucumber

(::) failed steps (::)


Could not find field: "Text" (Webrat::NotFoundError)
./features/step_definitions/web_steps.rb:36:in `/^(?:|I )fill in "([^"]*)" with "([^"]*)"$/'
features/messages.feature:11:in `もし●●する'


Failing Scenarios:
cucumber features/messages.feature:8 # Scenario: ××すると、△△される


2 scenarios (1 failed, 1 passed)
10 steps (1 failed, 2 skipped, 7 passed)
0m1.137s

        • For error
          • $ vim features/step_definitions/web_steps.rb

When /^(?:|I )press "([^"]*)"$/ do |button|
# click_button(button)
end


When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
# fill_in(field, :with => value)
end

          • $ rake cucumber

Using the default profile...


2 scenarios (2 passed)
10 steps (10 passed)
0m1.018s

Rails3 Cucumber no.2

  • Terminal 起動
  • $ cd rails3/rails3_cucumber/
  • $ vim features/messages.feature

# language: ja


フィーチャ: ○○する
<役割>として、
<機能>したい。
なぜなら、<フィーチャーの価値>だからだ。


シナリオ: ××すると、△△される
前提 □□している
もし ●●する
かつ ▲▲する
ならば ■■されていること

  • $ rake cucumber

file default
Using the default profile...
F---


(::) failed steps (::)


Can't find mapping from "□□" to a path.
Now, go and add a mapping in
~/rails3/rails3_cucumber/features/support/paths.rb (RuntimeError)
./features/support/paths.rb:28:in `rescue in path_to'
./features/support/paths.rb:22:in `path_to'
./features/step_definitions/web_steps.rb:16:in `/^(?:|I )am on (.+)$/'
features/messages.feature:9:in `前提□□している'


Failing Scenarios:
cucumber features/messages.feature:8 # Scenario: ××すると、△△される


1 scenario (1 failed)
4 steps (1 failed, 3 skipped)
0m0.947s
rake aborted!

undefined method `visit' for # (NoMethodError)


1 scenario (1 failed)
4 steps (1 failed, 3 skipped)
0m0.933s
rake aborted!

  • For error
    • $ vim features/support/env.rb

 # config.mode = :rails
   config.mode = :rack

  • $ rake cucumber

You are being redirected. (RSpec::Expectations::ExpectationNotMetError)


1 scenario (1 failed)
4 steps (1 failed, 3 passed)
0m1.131s
rake aborted!

  • For error
    • $ vim features/step_definitions/web_steps.rb

 Then /^(?:|I )should see "([^"]*)"$/ do |text|
  if response.respond_to? :should
 # response.should contain(text)
  else
  assert_contain text
  end
 end

  • $ rake cucumber

Using the default profile...
....


1 scenario (1 passed)
4 steps (4 passed)
0m1.160s

Rails3 Cucumber no.1

  • Terminal 起動
  • $ cd rails3/
  • $ rails new rails3_cucumber -T
  • $ cd rails3_cucumber/
  • $ vim Gemfile

gem "rcov"
gem 'cucumber-rails'
gem 'cucumber'
gem 'rspec-rails'
gem 'autotest'
gem 'webrat'

  • $ vim config/application.rb

config.generators do |g|
 g.test_framework :rspec
end

   create .rspec
   create spec
   create spec/spec_helper.rb

  • $ rails generate cucumber:install ja --webrat --rspec

   create config/cucumber.yml
   create script/cucumber
    chmod script/cucumber
   create features/step_definitions
   create features/step_definitions/web_steps.rb
   create features/step_definitions/web_steps_ja.rb
   create features/support
   create features/support/paths.rb
   create features/support/env.rb
    exist lib/tasks
   create lib/tasks/cucumber.rake
    gsub config/database.yml
    gsub config/database.yml
    force config/database.yml

  • $ rails generate scaffold sample
  • $ rake db:migrate
  • $ rake spec

Pending:
 SamplesHelper add some examples to (or delete) /Users/ebacky/repos/git/StruggleRecord/rails3_cucumber/spec/helpers/samples_helper_spec.rb
# Not Yet Implemented
# ./spec/helpers/samples_helper_spec.rb:14
Sample add some examples to (or delete) /Users/ebacky/repos/git/StruggleRecord/rails3_cucumber/spec/models/sample_spec.rb
# Not Yet Implemented
# ./spec/models/sample_spec.rb:4


Finished in 0.5355 seconds
29 examples, 0 failures, 2 pending

  • $ rake cucumber

Using the default profile...




0 scenarios
0 steps
0m0.000s

cucumber-rails install

  • Terminal 起動
  • $ sudo gem install cucumber-rails

Successfully installed cucumber-rails-0.3.2
1 gem installed
Installing ri documentation for cucumber-rails-0.3.2...
Installing RDoc documentation for cucumber-rails-0.3.2...

Cucumber install

  • Terminal 起動
  • sudo gem install cucumber

Building native extensions. This could take a while...
Building native extensions. This could take a while...


(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)


Thank you for installing cucumber-0.10.0.
Please be sure to read http://wiki.github.com/aslakhellesoy/cucumber/upgrading
for important information about this release. Happy cuking!


(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)


Successfully installed json-1.4.6
Successfully installed gherkin-2.3.3
Successfully installed term-ansicolor-1.0.5
Successfully installed cucumber-0.10.0
4 gems installed
Installing ri documentation for json-1.4.6...
Installing ri documentation for gherkin-2.3.3...
Installing ri documentation for term-ansicolor-1.0.5...
Installing ri documentation for cucumber-0.10.0...
Installing RDoc documentation for json-1.4.6...
Installing RDoc documentation for gherkin-2.3.3...
Installing RDoc documentation for term-ansicolor-1.0.5...
Installing RDoc documentation for cucumber-0.10.0...

Rails3 RSpec no.1

  • Terminal 起動
  • $ cd rails3/
  • $ rails new rails3_rspec -T
  • $ cd rails3_rspec/
  • $ vim Gemfile

gem "rcov"
group :development, :test do
 gem 'rspec-rails', :group => :development
 gem 'autotest', :group => :development
 gem 'webrat'
end

  • $ bundle install
  • $ bundle show
  • $ vim config/application.rb

config.generators do |g|
 g.test_framework :rspec
end

   create .rspec
   create spec
   create spec/spec_helper.rb

  • $ rails generate scaffold sample
  • $ rake db:migrate
  • $ rake db:test:prepare
  • $ rake spec

Finished in 0.51448 seconds
32 examples, 0 failures, 4 pending

rspec-rails install

  • Terminal 起動
  • $ cd rails3/sample/
  • $ vim Gemfile

gem 'rspec-rails'

  • $ bundle install

Fetching source index for http://rubygems.org/
Enter your password to install the bundled RubyGems to your system:
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.4)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.4)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.7)
Using tzinfo (0.3.24)
Using actionpack (3.0.4)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.15)
Using actionmailer (3.0.4)
Using arel (2.0.8)
Using activerecord (3.0.4)
Using activeresource (3.0.4)
Using bundler (1.0.10)
Using diff-lcs (1.1.2)
Using thor (0.14.6)
Using railties (3.0.4)
Using rails (3.0.4)
Using rspec-core (2.5.1)
Using rspec-expectations (2.5.0)
Using rspec-mocks (2.5.0)
Using rspec (2.5.0)
Installing rspec-rails (2.5.0)
Installing sqlite3 (1.3.3) with native extensions
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.