} Context("when arguments are provided", func() { var cmd commandregistry.Command var flagContext flags.FlagContext BeforeEach(func() { cmd = &buildpack.ListBuildpacks{} cmd.SetDependency(deps, false) flagContext = flags.NewFlagContext(cmd.MetaData().Flags) }) It("should fail with usage", func() { flagContext.Parse("blahblah") reqs, err := cmd.Requirements(requirementsFactory, flagContext) Expect(err).NotTo(HaveOccurred()) err = testcmd.RunRequirements(reqs) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(ContainSubstring("Incorrect Usage")) Expect(err.Error()).To(ContainSubstring("No argument required")) }) }) It("fails requirements when login fails", func() { requirementsFactory.NewLoginRequirementReturns(requirements.Failing{Message: "not logged in"}) Expect(runCommand()).To(BeFalse()) }) Context("when logged in", func() {
userRequirement.ExecuteReturns(nil) factory.NewUserRequirementReturns(userRequirement) organizationRequirement = new(requirementsfakes.FakeOrganizationRequirement) organizationRequirement.ExecuteReturns(nil) factory.NewOrganizationRequirementReturns(organizationRequirement) }) Describe("Requirements", func() { Context("when not provided exactly three args", func() { BeforeEach(func() { flagContext.Parse("the-user-name", "the-org-name") }) It("fails with usage", func() { _, err := cmd.Requirements(factory, flagContext) Expect(err).To(HaveOccurred()) Expect(ui.Outputs()).To(ContainSubstrings( []string{"Incorrect Usage. Requires USERNAME, ORG, ROLE as arguments"}, []string{"NAME"}, []string{"USAGE"}, )) }) }) Context("when provided three args", func() { BeforeEach(func() { flagContext.Parse("the-user-name", "the-org-name", "OrgManager") }) It("returns a LoginRequirement", func() {