Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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