{"id":160,"date":"2015-04-12T17:30:12","date_gmt":"2015-04-12T08:30:12","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2015\/04\/12\/rspec-ckeditor"},"modified":"2022-10-26T10:08:15","modified_gmt":"2022-10-26T01:08:15","slug":"rspec-ckeditor","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2015\/04\/12\/rspec-ckeditor\/","title":{"rendered":"rspec\u3067CKEditor\u306e\u30c6\u30b9\u30c8"},"content":{"rendered":"

\u30bb\u30d6\u3067\u82f1\u8a9e\u3092\u5b66\u3073\u306b\u884c\u304d\u307e\u3057\u305f\u304c\u82f1\u8a9e\u529b\u304c\u5168\u7136\u4e0a\u304c\u3063\u3066\u3044\u306a\u3044\u524d\u7530\u3067\u3059\u3002<\/p>\n

\u73fe\u5728\u958b\u767a\u3057\u3066\u3044\u308bweb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3001ckeditor gem\u3092\u4f7f\u7528\u3057\u3066CKEditor\u3092\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002
\n\u305d\u306efeature\u30c6\u30b9\u30c8\u3092\u5b9f\u88c5\u3059\u308b\u969b\u306b\u3001Capybara\u3067CKEditor\u306e\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5024\u3092\u5165\u529b\u3059\u308b\u30c6\u30b9\u30c8\u3067\u8a70\u307e\u3063\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3001\u3069\u306e\u3088\u3046\u306b\u5b9f\u88c5\u3057\u305f\u304b\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n

\u9069\u5f53\u306bRails\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3057\u3001feature\u30c6\u30b9\u30c8\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n

\u7528\u610f\u3057\u305f\u306e\u306f\u3053\u3093\u306a\u753b\u9762\u3067\u3059\u3002<\/p>\n

\"\"<\/p>\n

Capybara\u3092\u4f7f\u3063\u3066\u66f8\u304f\u3068\u666e\u901a\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3088\u306d\u3002<\/p>\n

require 'rails_helper'\n\ndescribe Admin::BooksController, type: :feature do\n\n  describe '#create' do\n    scenario 'should create book', js: true do\n\n      visit '\/books\/new'\n\n      fill_in '\u30bf\u30a4\u30c8\u30eb', with: '\u30bf\u30a4\u30c8\u30eb'\n      fill_in '\u30b3\u30f3\u30c6\u30f3\u30c4', with: '\u30b3\u30f3\u30c6\u30f3\u30c4'\n\n      click_link 'Create Book'\n    end\n  end\nend<\/code><\/pre>\n

\u305f\u3060\u3057\u3001fill_in\u30e1\u30bd\u30c3\u30c9\u306f\u666e\u901a\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3084\u30c6\u30ad\u30b9\u30c8\u30a8\u30ea\u30a2\u306a\u3069\u306f\u6587\u5b57\u3092\u5165\u529b\u3057\u3066\u304f\u308c\u307e\u3059\u304c\u3001CKEditor\u3092\u4f7f\u7528\u3057\u305f\u90e8\u5206\u306f\u5165\u529b\u3057\u3066\u304f\u308c\u307e\u305b\u3093\u3002<\/p>\n

\u305d\u3053\u3067\u3001spec\/support\/\u914d\u4e0b\u306b\u4e0b\u8a18\u30d5\u30a1\u30a4\u30eb\u3092\u6e96\u5099\u3057\u3001spec\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n

# Ckeditor\nmodule Ckeditor\n  def fill_in_ckeditor(locator, opts)\n    content = opts.fetch(:with).to_json\n    page.execute_script <<-SCRIPT\n      CKEDITOR.instances['#{locator}'].setData(#{content});\n      $('textarea##{locator}').text(#{content});\n    SCRIPT\n  end\nend<\/code><\/pre>\n

spec\/rails_helper.rb\u306b\u4e0b\u8a18\u4e00\u6587\u3092\u52a0\u3048\u307e\u3059\u3002<\/p>\n

~ \u7565 ~\n\n RSpec.configure do |config|\n   include Ckeditor\n\n~ \u7565 ~<\/code><\/pre>\n

\u305d\u3046\u3059\u308b\u3068\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306bfill_in\u30e1\u30bd\u30c3\u30c9\u306e\u3088\u3046\u306b\u4f7f\u3046\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f\u3002<\/p>\n

require 'rails_helper'\n\ndescribe Admin::BooksController, type: :feature do\n\n  describe '#create' do\n    scenario 'should create book', js: true do\n\n      visit '\/books\/new'\n\n      fill_in '\u30bf\u30a4\u30c8\u30eb', with: '\u30bf\u30a4\u30c8\u30eb'\n      fill_in_ckeditor :book_content, with: '\u30b3\u30f3\u30c6\u30f3\u30c4'\n      # :book_content\u306fckeditor\u304c\u4f7f\u7528\u3055\u308c\u3066\u3044\u308btextarea id\n\n      click_link 'Create Book'\n    end\n  end\nend<\/code><\/pre>\n

fill_in_ckeditor\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u306f\u4e0b\u8a18\u306eStack Overflow\u30da\u30fc\u30b8\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u3002
\nHow to fill ckeditor from capybara with webkit or selenium driver<\/a><\/p>\n

\u4eca\u307e\u3067\u306fRails\u3067API\u3092\u4e3b\u306b\u4f5c\u6210\u3057\u3066\u304a\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u753b\u9762\u64cd\u4f5c\u306b\u306f\u65e5\u3005\u60aa\u6226\u82e6\u95d8\u3057\u3066\u304a\u308a\u307e\u3059\u3002
\n\u5c11\u3057\u3065\u3064\u3067\u3082\u7a4d\u307f\u91cd\u306d\u3066\u3044\u304d\u3001\u4e00\u65e5\u3067\u3082\u65e9\u304fRails\u30de\u30b9\u30bf\u30fc\u306b\u306a\u308a\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

Ruby on Rails\u3092\u6d3b\u7528\u3057\u305fWeb\u30b5\u30fc\u30d3\u30b9\u3084\u696d\u52d9\u30b7\u30b9\u30c6\u30e0\u958b\u767a<\/a>\u3092\u3054\u691c\u8a0e\u306e\u4f01\u696d\u69d8\u306f\u3001\u662f\u975eMMM\u306b\u3054\u76f8\u8ac7\u4e0b\u3055\u3044\u307e\u305b\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

\u30bb\u30d6\u3067\u82f1\u8a9e\u3092\u5b66\u3073\u306b\u884c\u304d\u307e\u3057\u305f\u304c\u82f1\u8a9e\u529b\u304c\u5168\u7136\u4e0a\u304c\u3063\u3066\u3044\u306a\u3044\u524d\u7530\u3067\u3059\u3002 \u73fe\u5728\u958b\u767a\u3057\u3066\u3044\u308bweb\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3001ckeditor gem\u3092\u4f7f\u7528\u3057\u3066CKEditor\u3092\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002 \u305d\u306efeature\u30c6\u30b9\u30c8\u3092\u5b9f\u88c5\u3059\u308b\u969b\u306b\u3001Capybara\u3067CKEditor\u306e\u30c6\u30ad\u30b9\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5024\u3092\u5165\u529b\u3059\u308b\u30c6\u30b9\u30c8\u3067\u8a70\u307e\u3063\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3001\u3069\u306e\u3088\u3046\u306b\u5b9f\u88c5\u3057\u305f\u304b\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002 \u9069\u5f53\u306bRails\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3057\u3001featur […]<\/p>\n","protected":false},"author":1,"featured_media":684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[9],"tags":[42],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/160"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":1,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":3365,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/160\/revisions\/3365"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}