Skip to content

Commit

Permalink
RYS add feature to existing plugin and for this needs their Factories (
Browse files Browse the repository at this point in the history
…#23)

* RYS add feature to existing plugin and for this needs their Factories

* improve naming
  • Loading branch information
luk4s authored Jul 9, 2021
1 parent 9d4d166 commit cf18c58
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inherit_gem:
easy_style: default.yml
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Shortcut for require factories from redmine plugins

## [0.2.18] - 2020-07-07
### Fixed
- init support and factories files in systemic rysy
Expand Down
16 changes: 16 additions & 0 deletions lib/ryspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,20 @@
require 'ryspec/engine'

module Ryspec

# @param [String, Symbol] plugin_name of Redmine plugin (Symbol is preferred)
# @param [String] file_name of factory in `test/factories` (by default its name of plugin)
# @param [String, Symbol] factory_name of FactoryBot.define (by default its equal to filename)
#
# @example Ryspec.require_factory :easy_contacts, file_name: "easy_contact"
def self.require_factory(plugin_name, file_name: nil, factory_name: nil)
factory_name ||= file_name || plugin_name
return if FactoryBot.factories.registered? factory_name

factory_file = File.join(Redmine::Plugin.find(name).directory, "/test/factories/#{file_name || plugin_name}")
raise ArgumentError, "File `#{factory_file}` doesnt exists!" unless File.exist?(factory_file)

require factory_file
end

end
4 changes: 3 additions & 1 deletion lib/ryspec/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Ryspec
VERSION = '0.3.0'

VERSION = '0.4.0'

end
26 changes: 13 additions & 13 deletions ryspec.gemspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# encoding: utf-8

$:.push File.expand_path('lib', __dir__)
$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'ryspec/version'

Gem::Specification.new do |s|
s.name = 'ryspec'
s.version = Ryspec::VERSION
s.authors = ['Ondřej Moravčík']
s.email = ['info@easysoftware.com']
s.homepage = 'https://easysoftware.com'
s.summary = 'Summary of Ryspec.'
s.description = 'Description of Ryspec.'
s.license = 'GPL-2.0-or-later'
s.name = 'ryspec'
s.version = Ryspec::VERSION
s.authors = ['Ondřej Moravčík', 'Lukáš Pokorný']
s.email = ['info@easysoftware.com']
s.homepage = 'https://github.com/easysoftware/ryspec'
s.summary = 'RSpec basics for RYSy.'
s.description = 'Define spec_helper, Redmine factories and some helpers for RSpec in RYSy ecosystem.'
s.license = 'GPL-2.0-or-later'

s.metadata['allowed_push_host'] = 'https://gems.easysoftware.com'

s.files = Dir['{app,config,db,lib,patches}/**/{*,.*}', 'Rakefile', 'README.md', 'gems.rb']
s.test_files = Dir['spec/**/*']

s.add_dependency 'rys'
s.add_dependency 'rspec-rails', '~> 5.0'
s.add_dependency 'capybara'
s.add_dependency 'database_cleaner-active_record', '~> 2.0.0'
s.add_dependency 'factory_bot_rails', '~> 6.1'
s.add_dependency 'rspec-rails', '~> 5.0'
s.add_dependency 'rys'
s.add_dependency 'webmock', '~> 3.12.2'

s.add_development_dependency 'easy_style'
end
12 changes: 12 additions & 0 deletions spec/rsypec_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RSpec.describe Ryspec do
describe ".require_factory" do
it "undefine plugin raise error" do
expect { described_class.require_factory :dummy_plugin }.to raise_error Redmine::PluginNotFound
end

it "plugin exist but factory file not" do
allow(Redmine::Plugin).to receive(:find).and_return double("plugin", directory: Rails.root.join("plugins/easy_contacts"))
expect { described_class.require_factory :easy_contacts }.to raise_error ArgumentError
end
end
end

0 comments on commit cf18c58

Please sign in to comment.