spec/lib/pdksync_spec.rb in pdksync-0.1.0 vs spec/lib/pdksync_spec.rb in pdksync-0.2.0
- old
+ new
@@ -3,66 +3,52 @@
require 'fileutils'
require 'octokit'
describe PdkSync do
before(:all) do
- @timestamp = Time.now.to_i
- @namespace = 'puppetlabs'
@pdksync_dir = './modules_pdksync'
- @module_name = 'puppetlabs-testing'
- @output_path = "#{@pdksync_dir}/#{@module_name}"
- @access_token = ENV['GITHUB_TOKEN']
- @repo_name = "#{@namespace}/#{@module_name}"
+ module_name = 'puppetlabs-testing'
+ @module_names = ['puppetlabs-testing']
+ @output_path = "#{@pdksync_dir}/#{module_name}"
+ @folder = Dir.pwd
end
- context 'env' do
- it 'has a filespace' do
+ before(:each) do
+ allow(PdkSync).to receive(:return_modules).and_return(@module_names)
+ Dir.chdir(@folder)
+ end
+
+ context 'main method' do
+ it 'runs clone sucessfully' do
FileUtils.rm_rf(@pdksync_dir)
PdkSync.create_filespace
+ PdkSync.main(steps: [:clone])
expect(Dir.exist?(@pdksync_dir)).to be(true)
- end
-
- it 'has cloned the repo' do
- PdkSync.clone_directory(@namespace, @module_name, @output_path)
expect(Dir.exist?(@output_path)).to be(true)
end
- end
-
- context 'run' do
- before(:all) do
- @git_repo = Git.open(@output_path)
+ it 'runs pdk convert, and files have changed' do
+ PdkSync.main(steps: [:pdk_convert])
+ File.exist?("#{@output_path}/convert_report.txt")
end
-
- it 'has created a branch' do
- PdkSync.checkout_branch(@git_repo, @timestamp)
- expect(@git_repo.current_branch).to include(@timestamp.to_s)
+ it 'raise when running a command with no argument' do
+ expect { PdkSync.main(steps: [:run_a_command]) }.to raise_error(RuntimeError, %r{"run_a_command" requires an argument to run.})
end
-
- it 'has created a report' do
- FileUtils.rm_rf('update_report.txt')
- PdkSync.pdk_update(@output_path)
- expect(File.exist?('update_report.txt')).to be(true)
+ it 'runs a command "touch cat.meow"' do
+ PdkSync.main(steps: [:run_a_command], args: 'touch cat.meow')
+ expect File.exist?("#{@output_path}/cat.meow")
end
-
- it 'has staged files' do
- PdkSync.add_staged_files(@git_repo)
- result = Open3.capture3('git status')
- expect(result).to include(%r{Changes to be committed})
+ it 'raise when create_commit with no arguments' do
+ expect { PdkSync.main(steps: [:create_commit]) }.to raise_error(RuntimeError, %r{Needs a branch_name and commit_message})
end
-
- it 'has committed files' do
- pre_commit = @git_repo.log.last
- PdkSync.commit_staged_files(@git_repo, @timestamp)
- post_commit = @git_repo.log.last
- expect(pre_commit).not_to eq(post_commit)
+ it 'create_commit runs, and contains the "kittens in mittens"' do
+ PdkSync.main(steps: [:create_commit], args: { branch_name: 'temp_branch', commit_message: 'kittens in mittens' })
+ git_repo = Git.open(@output_path)
+ expect(git_repo.show).to include('kittens in mittens')
end
+ it 'raise when push_and_create_pr with no arguments' do
+ expect { PdkSync.main(steps: [:push_and_create_pr]) }.to raise_error(RuntimeError, %r{Needs a pr_title})
+ end
+ it 'raise when clean_branches with no arguments' do
+ expect { PdkSync.main(steps: [:clean_branches]) }.to raise_error(RuntimeError, %r{Needs a branch_name, and the branch name contains the string pdksync})
+ end
end
- # # Test fails if ran from travis due to lack of proper credentials
- # it 'The committed files should be pushed and the PR created', unless: @access_token == '' do
- # @client = PdkSync.setup_client
- # PdkSync.push_staged_files(@git_repo, @timestamp, @repo_name)
- # pr = PdkSync.create_pr(@client, @repo_name, @timestamp, @timstamp)
- # expect(pr.title).to eq("pdksync - pdksync_#{@timestamp}")
- # #Branch is now cleaned
- # PdkSync.delete_branch(@client, @repo_name, "pdksync_#{@timestamp}".to_s)
- # end
end