File: rails_steps.rb

package info (click to toggle)
ruby-factory-bot-rails 6.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 316 kB
  • sloc: ruby: 635; makefile: 6; sh: 4
file content (62 lines) | stat: -rw-r--r-- 1,618 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
When(/^I create a new rails application$/) do
  options =
    %w[
      --api
      --skip-bootsnap
      --skip-javascript
      --skip-action-mailer
      --skip-active-storage
      --skip-action-cable
      --skip-sprockets
      --skip-bundle
    ].join(" ")

  template = "-m ../../features/support/rails_template"
  result = run_command("bundle exec rails new test_app #{options} #{template}")

  expect(result).to have_output(/README/)
  expect(last_command_started).to be_successfully_executed

  cd("test_app")
end

When(/^I add "([^"]+)" from this project as a dependency$/) do |gem_name|
  append_to_file("Gemfile", %(gem "#{gem_name}", :path => "#{PROJECT_ROOT}"\n))
end

When(/^I add "([^"]+)" as a dependency$/) do |gem_name|
  append_to_file("Gemfile", %(gem "#{gem_name}"\n))
end

When(/^I print out "([^"]*)"$/) do |path|
  in_current_dir do
    File.open(path, "r") do |f|
      puts f.inspect
    end
  end
end

When(/^I configure the factories as:$/) do |string|
  append_to_file File.join("config", "application.rb"), <<~RUBY
    class TestApp::Application
      #{string}
    end
  RUBY
end

When(/^I configure the factories directory as "([^"]+)"$/) do |factory_dir|
  append_to_file File.join("config", "application.rb"), <<~RUBY
    class TestApp::Application
      config.generators do |g|
        g.fixture_replacement :factory_bot, :dir => "#{factory_dir}"
      end
    end
  RUBY
end

When(/^I comment out gem "([^"]*)" from my Gemfile$/) do |gem_name|
  in_current_dir do
    content = File.read("Gemfile")
    File.write("Gemfile", content.sub(/gem ['"]#{gem_name}/, '#\1'))
  end
end